Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speculatively-instantiated templates are incorrectly cached #17887

Open
dlangBugzillaToGithub opened this issue Dec 1, 2018 · 0 comments
Open
Labels

Comments

@dlangBugzillaToGithub
Copy link

Paul Backus (@pbackus) reported this on 2018-12-01T03:21:09Z

Transferred from https://issues.dlang.org/show_bug.cgi?id=19458

CC List

Description

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant