[Issue 2614] New: auto + templated structs = unhelpful error messages

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Jan 24 13:38:21 PST 2009


http://d.puremagic.com/issues/show_bug.cgi?id=2614

           Summary: auto + templated structs = unhelpful error messages
           Product: D
           Version: unspecified
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: andrei at metalanguage.com


#!/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.


-- 



More information about the Digitalmars-d-bugs mailing list