Bug 1515 – compiler accepts invalid template declaration

Status
RESOLVED
Resolution
WONTFIX
Severity
trivial
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
All
OS
Windows
Creation time
2007-09-18T04:11:00Z
Last change time
2019-08-21T11:03:40Z
Assigned to
No Owner
Creator
david

Comments

Comment #0 by davidl — 2007-09-18T04:11:00Z
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;
Comment #1 by smjg — 2007-10-29T07:52:38Z
AIUI this is by design, though admittedly it's a rather strange design. http://www.digitalmars.com/d/1.0/template.html 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.
Comment #2 by razvan.nitu1305 — 2019-08-21T11:03:40Z
The template is not semantically analyzed before instantiation, it is only parsed, so the compiler cannot reject the template definition before actually instantiating it. This is clearly stated in the spec. The error message points this out: "mixin test.B!(A!int) does not match template declaration B(T : A!T)". Closing as WONTFIX.