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: nob...@puremagic.com
          Reporter: bugzi...@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.

--

Reply via email to