www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 1515] New: compiler accepts invalid template declaration

reply d-bugmail puremagic.com writes:

           Summary: compiler accepts invalid template declaration
           Product: D
           Version: 1.014
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: trivial
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla digitalmars.com
        ReportedBy: davidl 126.com

template A(T)
        alias T type;
template B(T:A!(T).type)    // I think compiler should ban the use of reuse the
same type identifier in the specialization part.
//mixin B!(int);  // even though you can't instantiate the template, the
compiler can actually emit nicer message;

Sep 18 2007
parent d-bugmail puremagic.com writes:

smjg iname.com changed:

           What    |Removed                     |Added
                 CC|                            |smjg iname.com

------- Comment #1 from smjg iname.com  2007-10-29 07:52 -------
AIUI this is by design, though admittedly it's a rather strange design.


template TBar(T : T*) { }
alias TBar!(char*) Foo3;        // (2) T is deduced to be char

Basically, what it means is that if a template parameter name is re-used as
part of the specialization, it has the meaning of 'anything', and within the
template, the identifier denotes what it represented within the specialization.

But where T is used as a template parameter in the specialization, I'm not sure
it can work in the general case.  After all, there's a potential infinitude of
templates to instantiate to try to find a match.  So I'm still not sure that
the compiler should accept the template declaration.

Oct 29 2007