Bug 22540 – Instantiation modifies dependant type of value / alias template parameters

Status
NEW
Severity
critical
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2021-11-23T20:15:28Z
Last change time
2024-12-13T19:19:25Z
Keywords
pull
Assigned to
No Owner
Creator
moonlightsentinel
See also
https://issues.dlang.org/show_bug.cgi?id=14501
Moved to GitHub: dmd#20011 →

Comments

Comment #0 by moonlightsentinel — 2021-11-23T20:15:28Z
Template instantiation can modify the type of value / alias parameters when it depends on a previous template parameters. This causes invalid errors for further instantiations. =========================================================== // Example for value parameters template Value(T = int, T* ptr = (T*).init) { pragma(msg, T, ": ", typeof(ptr), " => ", ptr); } alias v1 = Value!(double); // OK alias v2 = Value!(int); // Error: template instance `Value!int` does not match template declaration `Value(T = int, double* ptr = (T*).init)` // // Notice the `double* ptr` instead of `T* ptr` =========================================================== =========================================================== // Example for alias parameters template Alias(T = int, alias T* ptr = (T*).init) { pragma(msg, T, ": ", typeof(ptr), " => ", ptr); } alias a1 = Alias!(double); // Error: template instance `Alias!double` does not match template declaration `Alias(T = int, alias T* ptr = (double*).init)` alias a2 = Alias!(int); // Error: template instance `Alias!int` does not match template declaration `Alias(T = int, alias T* ptr = (double*).init)` ===========================================================
Comment #1 by dlang-bot — 2021-11-23T21:16:22Z
@MoonlightSentinel created dlang/dmd pull request #13352 "Fix 22540 - Copy parameter types / defaults of dependant template..." fixing this issue: - Fix 22540 - Copy parameter types / defaults of dependant template... ... value / alias parameters. The introduced copies ensure that the initialized parameters of the instantiation do not share objects with the template declaration. Previously, sharing could occur in the following scenarios: - type parameter appears inside of value type, e.g. `foo(T, T* val)` Later semantic resolves `T` to the concrete type and hence changes the type of `val` in the template declaration. - alias parameter default value isn't copied and manifested according to the first template instance. https://github.com/dlang/dmd/pull/13352
Comment #2 by razvan.nitu1305 — 2022-01-28T09:52:49Z
*** Issue 3538 has been marked as a duplicate of this issue. ***
Comment #3 by razvan.nitu1305 — 2022-01-28T09:55:11Z
*** Issue 18910 has been marked as a duplicate of this issue. ***
Comment #4 by razvan.nitu1305 — 2022-01-28T09:56:18Z
*** Issue 20576 has been marked as a duplicate of this issue. ***
Comment #5 by razvan.nitu1305 — 2022-01-28T09:56:41Z
*** Issue 18917 has been marked as a duplicate of this issue. ***
Comment #6 by robert.schadek — 2024-12-13T19:19:25Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/20011 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB