Bug 11662 – Template constraint evaluation should not look eponymous template function parameters if it's unnecessary

Status
NEW
Severity
critical
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-12-01T21:17:11Z
Last change time
2024-12-13T18:14:53Z
Keywords
rejects-valid
Assigned to
No Owner
Creator
Kenji Hara
Moved to GitHub: dmd#17630 →

Comments

Comment #0 by k.hara.pg — 2013-12-01T21:17:11Z
Both template functions should work, but doesn't. template gc_free1(T) { alias Type = T*; void gc_free1(Type data) {} } template gc_free2(T) if (!is(T == class)) { alias Type = T*; void gc_free2(Type data) {} } void main() { int* p; gc_free1!int(p); // OK gc_free2!int(p); // Error: undefined identifier Type }
Comment #1 by k.hara.pg — 2013-12-01T21:21:30Z
With git head, the OP code causes compiler segfault. https://github.com/D-Programming-Language/dmd/pull/2910
Comment #2 by nick — 2023-03-31T10:52:06Z
Still doesn't work: temcons.d(17): Error: template instance `temcons.gc_free2!int` does not match template declaration `gc_free2(T)(Type data)` And you can't even alias the template instance: alias a = gc_free2!int; // same error
Comment #3 by b2.temp — 2023-10-16T08:41:01Z
More precisely the problem is here [1]. DMD tries to define the type of the eponymous member (the `onemember` symbol) but using an inadequate scope since it does not allow to resolve `Type`, as you can see when the gagging "sandwich" code is deactivated... Problem is that the right scope simply does not exist yet. [1]: https://github.com/dlang/dmd/blob/daf1a31c5f97df3d3082dd5a332422ba5c3ae20b/compiler/src/dmd/dtemplate.d#L1190
Comment #4 by b2.temp — 2023-10-16T08:55:00Z
*** Issue 13580 has been marked as a duplicate of this issue. ***
Comment #5 by robert.schadek — 2024-12-13T18:14:53Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/17630 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB