Issues with constants, and inout (was Real World usage of D, Today)
Frits van Bommel
fvbommel at REMwOVExCAPSs.nl
Mon Jan 29 05:41:10 PST 2007
Oskar Linde wrote:
> Frits van Bommel wrote:
>> It's a bit more complicated with character literals than just
>> defaulting to 'char':
> [snip typeof('e') == char, typeof('é') == wchar, ...]]
>> So it defaults to the *smallest* character type that can hold it in
>> one element.
>> Pretty cool, actually.
>
> A problem related to this, that might actually warrant a bug report, is
> that given:
>
> char[] str = "abcd";
>
> str ~= 'e';
> writefln(str);
>
> Is OK, while
>
> str ~= 'é';
> writefln(str);
>
> Generates an invalid UTF-8 string ant gives the runtime "Error: 4invalid
> UTF-8 sequence"
>
> It seems like the wchar 'é' gets int-promoted to 0xE9 that is different
> from the char[] (utf-8) representation of "é", that would be x"C3 A9".
Yes, that probably warrants a bug report. Either an error should be
produced (something like "Invalid operation: str ~= 'é', cannot
concatenate wchar to char[]"), or (preferably) it should just work.
The latter can (for example) be implemented by doing the equivalent of
std.utf.encode(str, 'é'), or the equivalent of str ~= "é" (note the
quotes, implicitly converting it to char[] instead of wchar).
More information about the Digitalmars-d
mailing list