Bug 2614 – auto + templated structs = unhelpful error messages

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Linux
Creation time
2009-01-24T15:38:00Z
Last change time
2014-02-14T20:35:09Z
Keywords
diagnostic
Assigned to
bugzilla
Creator
andrei

Comments

Comment #0 by andrei — 2009-01-24T15:38:22Z
#!/home/andrei/bin/rdmd struct S(T) { this(int x) { wrong_code; } } void main() { auto s = S!(int)(42); } Attempting to compile this code yields: ./test.d(4): struct test.S(T) is not a function template ./test.d(13): struct test.S(T) cannot deduce template function from argument types !(int)(int) This does not reveal where the problem is (namely, symbol wrong_code does not exist). I traced back the problem to the use of auto. If I change the line in main with: S!(int) s = S!(int)(42); then the error message becomes meaningful: ./test.d(7): Error: undefined identifier wrong_code ./test.d(7): Error: identifier has no effect in expression (wrong_code) ./test.d(13): template instance test.S!(int) error instantiating This is a killer in debugging larger templates with indirect instantiation patterns.
Comment #1 by wbaxter — 2009-01-25T18:16:48Z
See also #2510
Comment #2 by wbaxter — 2009-01-25T18:19:09Z
(In reply to comment #1) > See also #2510 > Feh, I always forget what magic invocation creates a hyperlink so here's a regular url: http://d.puremagic.com/issues/show_bug.cgi?id=2510 And some more attempts issue 2510 number 2510 bug 2510
Comment #3 by bugzilla — 2009-03-01T04:38:29Z
The problem here is that S!(int)(42) can be either a template followed by (42), or a function template with argument list (42). The compiler cannot tell. So first it tries the former, and it silently fails (due to the wrong_code). Then, it figures it must be a function template, and tries that. That fails too, hence the error message you see. The reason: S!(int) s = S!(int)(42); gives a more correct message is the left S!(int) type is compiled first, and by the syntax the compiler knows it's not a function template, so instead of silently failing it verbosely fails. So what to do if both tries at instantiating it fail? Print the first error message, or the second? One will not make sense.
Comment #4 by k.hara.pg — 2011-04-18T12:17:17Z
Trunk dmd(Commit:2e261cd640e5266c569ad224ffbfe229a0315d97) prints following messages. test.d(5): Error: undefined identifier wrong_code test.d(11): Error: template instance test.S!(int) error instantiating I think this issue was resolved.