Bug 8044 – Print names, not casted values when using enum template parameter

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-05-04T20:33:56Z
Last change time
2020-10-15T00:30:10Z
Keywords
diagnostic, pull
Assigned to
No Owner
Creator
Andrej Mitrovic

Comments

Comment #0 by andrej.mitrovich — 2012-05-04T20:33:56Z
enum Enum { Foo, Bar } void test(Enum en)() if(0) { } void main() { test!(Enum.Bar)(); } test.d(11): Error: template instance test!(cast(Enum)1) test!(cast(Enum)1) does not match template declaration test(Enum en) if (0) test.d(11): Error: function expected before (), not test!(cast(Enum)1) of type void This is really awful because when you have over a few dozen fields in an enum you end up having to count the fields to figure out which enum value was actually used when instantiating the template. (Either that or having to insert a to!string call just for debugging). The above errors should be: test.d(11): Error: template instance test!(Enum.Bar) test!(Enum.Bar) does not match template declaration test(Enum en) if (0) test.d(11): Error: function expected before (), not test!(Enum.Bar) of type void
Comment #1 by bearophile_hugs — 2012-05-06T06:50:44Z
See also Issue 5004
Comment #2 by bearophile_hugs — 2014-02-02T07:40:43Z
Related problem: import std.stdio; enum Foo { A, B } const Foo f = Foo.A; enum Bar : ubyte { C, D } const Bar b = Bar.C; void main() { pragma(msg, f, " ", b); writeln(f, " ", b); } Output: cast(Foo)0 cast(Bar)cast(ubyte)0u A C Expected output: A C A C
Comment #3 by dlang-bot — 2020-10-09T23:18:25Z
@Geod24 created dlang/dmd pull request #11841 "Fix 8044 - Print name of enum passed a tmpl param" fixing this issue: - Fix 8044 - Print name of enum passed a tmpl param https://github.com/dlang/dmd/pull/11841
Comment #4 by pro.mathias.lang — 2020-10-10T00:11:11Z
*** Issue 14067 has been marked as a duplicate of this issue. ***
Comment #5 by pro.mathias.lang — 2020-10-10T00:12:16Z
*** Issue 18479 has been marked as a duplicate of this issue. ***
Comment #6 by dlang-bot — 2020-10-15T00:30:10Z
dlang/dmd pull request #11841 "Fix 8044 - Print name of enum passed a tmpl param" was merged into master: - 05bf5a11d82676f56751e3e69482df6c22c33a31 by Geod24: Fix 8044 - Print name of enum passed a tmpl param https://github.com/dlang/dmd/pull/11841