On 05.02.2018 22:56, Walter Bright wrote:
On 2/5/2018 12:45 PM, H. S. Teoh wrote:
Sticking to C promotion rules is one of the scourges that continue to
plague D;
It's necessary. Working C expressions cannot be converted to D while
introducing subtle changes in behavior.
...
Neither byte nor dchar are C types.
another example is char -> byte confusion no thanks to C
traditions:
int f(dchar ch) { return 1; }
int f(byte i) { return 2; }
void main() {
pragma(msg, f('a'));
pragma(msg, f(1));
}
Exercise for reader: guess compiler output.
'a' and 1 do not match dchar or byte exactly, and require implicit
conversions. D doesn't have the C++ notion of "better" implicit
conversions for function arguments, instead it uses the
"leastAsSpecialized" C++ notion used for template matching, which is
better.
The idea is a byte can be implicitly converted to a dchar, but not the
other way around. Hence, f(byte) is selected as being the "most
specialized" match.
The overloading rules are fine, but byte should not implicitly convert
to char/dchar, and char should not implicitly convert to byte.