www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 2614] New: auto + templated structs = unhelpful error messages

reply d-bugmail puremagic.com writes:
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 digitalmars.com
        ReportedBy: andrei 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.


-- 
Jan 24 2009
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2614





------- Comment #1 from wbaxter gmail.com  2009-01-25 18:16 -------
See also #2510 


-- 
Jan 25 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2614





------- Comment #2 from wbaxter gmail.com  2009-01-25 18:19 -------
(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 --
Jan 25 2009
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2614





------- Comment #3 from bugzilla digitalmars.com  2009-03-01 04:38 -------
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.


-- 
Mar 01 2009
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=2614


Kenji Hara <k.hara.pg gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |k.hara.pg gmail.com


--- Comment #4 from Kenji Hara <k.hara.pg gmail.com> 2011-04-18 12:17:17 PDT ---
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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Apr 18 2011