[Issue 14519] New: [Enh] foreach on strings should return replacementDchar rather than throwing
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Tue Apr 28 18:42:53 PDT 2015
https://issues.dlang.org/show_bug.cgi?id=14519
Issue ID: 14519
Summary: [Enh] foreach on strings should return
replacementDchar rather than throwing
Product: D
Version: D2
Hardware: All
OS: All
Status: NEW
Severity: enhancement
Priority: P1
Component: DMD
Assignee: nobody at puremagic.com
Reporter: bugzilla at digitalmars.com
Consider:
@safe pure nothrow @nogc void bar();
void foo(string s) @safe pure nothrow @nogc {
foreach (dchar c; s)
bar();
}
This fails to compile because foreach over a decoded string can throw. It also
incorrectly is regarded as @nogc, because the throw can allocate.
Changing foreach to return replacementDchar on invalid UTF encodings fixes
these problems, and makes it possible to do faster loops.
--
More information about the Digitalmars-d-bugs
mailing list