Weird overload resolution (or rather, lack thereof) for literals

Thomas Kuehne thomas-dloop at kuehne.cn
Sun May 21 11:51:22 PDT 2006


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Stewart Gordon schrieb am 2005-10-13:
> Using DMD 0.131 (has DMD itself actually changed since then?), Windows 98SE.
>
> ----------
> enum Qwert { yuiop }
>
> void asdfg(Qwert hjkl) { printf("Called hjkl(Qwert)\n"); }
> void asdfg(uint zxcvb) { printf("Called hjkl(uint)\n"); }
>
> void main() {
>      int nm = 2;
>
>      asdfg(nm);
>      asdfg(cast(int) nm);
>      asdfg(3);
>      asdfg(cast(int) 3);
> }
> ----------
> D:\My Documents\Programming\D\Tests\implicit_enum.d(11): function 
> implicit_enum.asdfg called with argument types:
>      (int)
> matches both:
>      implicit_enum.asdfg(Qwert )
> and:
>      implicit_enum.asdfg(uint)
> D:\My Documents\Programming\D\Tests\implicit_enum.d(12): function 
> implicit_enum.asdfg called with argument types:
>      (int)
> matches both:
>      implicit_enum.asdfg(Qwert )
> and:
>      implicit_enum.asdfg(uint)
>
> Tool completed with exit code 1
> ----------
>
> For the integer variable, it manages to resolve the overload.  Indeed, 
> it calls the uint version.
>
> However, with the literal, it doesn't, even if it has been cast.  This 
> is absurd.  Just as integer variables don't implicitly convert to enums, 
> neither should integer literals.  And that line 10 passes but line 12 
> doesn't is even more absurd, as both have the same type set in the same 
> amount of stone.

Added to DStress as
http://dstress.kuehne.cn/run/o/overload_26_A.d
http://dstress.kuehne.cn/run/o/overload_26_B.d

Thomas


-----BEGIN PGP SIGNATURE-----

iD8DBQFEcL9q3w+/yD4P9tIRAvehAJ9qK4MMTukennpThWOTEbYz0o/HNwCgyGQI
655YZjqDsA9BA6QYNPZg4I4=
=PhVn
-----END PGP SIGNATURE-----



More information about the Digitalmars-d-bugs mailing list