Summary: auto + templated structs = unhelpful error messages
           Product: D
           Version: unspecified
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD


struct S(T)
    this(int x)

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


Reply via email to