Skip to content

Possible incorrect code generation when using variable templates #60373

@jonas-eschmann

Description

@jonas-eschmann

Hello,

I'm encountering an issue with member variables not being initialised properly after moving from GCC to Clang. I managed to boil it down to the following minimal example:

template <typename T>
struct A{
    int x = 10;
};

template <typename T>
struct B{
    A<T> a;
};

template <typename T>
A<T> a;

template <typename T>
auto aa = a<T>;

template <typename T>
B<T> b = {
    aa<T>
};

int main(){
    return b<float>.a.x;
}

Same example on the compiler explorer

I'm expecting it to return 10 (which GCC does) but Clang returns 0

Best regards!
Jonas

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"miscompilation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions