Deprecate implicit `int` to `bool` conversion for integer literals
Timon Gehr
timon.gehr at gmx.ch
Sat Nov 18 12:54:01 UTC 2017
On 15.11.2017 00:14, Michael V. Franklin wrote:
> On Tuesday, 14 November 2017 at 13:20:22 UTC, Nick Treleaven wrote:
>
>> An very similar problem exists for int and char overloads:
>>
>> alias foo = (char c) => 1;
>> alias foo = (int i) => 4;
>>
>> enum int e = 7;
>> static assert(foo(e) == 4); // fails
>
> Wait a minute! This doesn't appear to be a casting or overload
> problem. Can you really overload aliases in D?
> ...
Yes.
auto foo(int x){ return x; }
auto bar(double x){ return x+1; }
alias qux=foo;
alias qux=bar;
void main(){
import std.stdio;
writeln(qux(1)," ",qux(1.0)); // 1 2
}
This is by design. The fact that the following does not work is just a
(known) compiler bug:
alias qux=(int x)=>x;
alias qux=(double x)=>x+1;
void main(){
import std.stdio;
writeln(qux(1)," ",qux(1.0)); // error
}
https://issues.dlang.org/show_bug.cgi?id=16099
More information about the Digitalmars-d
mailing list