dmd foreach loops throw exceptions on invalid UTF sequences, use replacementDchar instead

Steven Schveighoffer schveiguy at gmail.com
Thu Nov 4 14:10:06 UTC 2021


On 11/3/21 10:26 PM, Walter Bright wrote:
> https://issues.dlang.org/show_bug.cgi?id=22473
> 
> I've tried to fix this before, but too many people objected.
> 
> Are we fed up with this yet? I sure am.
> 
> Who wants to take up this cudgel and fix the durned thing once and for all?
> 
> (It's unclear if it would even break existing code.)

Honestly, I'd say `foreach(dchar c; somestr)` should not work.

1. It's slow and calls opaque functions
2. Adds more requirements to runtime that are simply solved by basic 
wrappers.
3. If writing wrappers, you can decide what you want.
4. It gets people used to language-magic character conversion, when this 
doesn't work on ranges of `char` that aren't arrays -- which then 
performs integer promotion.

What I would *not* suggest though, is to just disable the feature. If it 
falls back to integer promotion (which is the worst thing ever for 
characters), then tons and tons of code will break, and much code will 
just work for English strings.

Autodecoding might be a huge problem with Phobos, but character 
promotion is a huge problem with the language.

-Steve


More information about the Digitalmars-d mailing list