Bug 19458 – Speculatively-instantiated templates are incorrectly cached

Status
NEW
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86_64
OS
Linux
Creation time
2018-12-01T03:21:09Z
Last change time
2024-12-13T19:01:30Z
Keywords
industry
Assigned to
No Owner
Creator
Paul Backus
Moved to GitHub: dmd#17887 →

Comments

Comment #0 by snarwin+bugzilla — 2018-12-01T03:21:09Z
Example program: --- test.d struct A { static if (__traits(compiles, hasFoo!A)) { void foo() {} } } enum hasFoo(T) = __traits(hasMember, T, "foo"); void main() { import std.stdio; writeln(hasFoo!A); // false (should be true) writeln(__traits(hasMember, A, "foo")); // true } --- Output: $ dmd test.d && ./test false true When `hasFoo!A` is instantiated in the `__traits(compiles)` expression, it evaluates to false, because the body of the `static if` statement has not been compiled yet. The same instantiation is then re-used in `main`, even though it is no longer semantically correct. Possibly related to issue 14803.
Comment #1 by robert.schadek — 2024-12-13T19:01:30Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/17887 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB