Skip to content

Possible incorrect code generation when using variable templates (again) #164691

@jonas-eschmann

Description

@jonas-eschmann

Hello,

I'm encountering issues with Clang when initializing nested, templated structs again. A similar, now solved issue is filed here.

I was able to boil it down to this:

https://godbolt.org/z/jvPeYed1x

template <typename T>
struct A {
    T* a = nullptr;
};

template <typename T>
struct B {
    struct {
        A<T> aa;
    } b;
};


float d[] = {0.1337};
A<float> aa = {d};
B<float> b = {
    {aa},
};

template <typename T>
struct C {
    B<T> b;
};

template <typename T>
T factory = {b};

C<float> c = {b};

int main() {
    return factory<C<float>>.b.b.aa.a == nullptr ? 100 : 0;
    // return c.b.b.aa.a == nullptr ? 100 : 0;
}

I expect this to return 0.

This fails in Clang when using the factory. When instantiating C directly it works.

It fails in all Clang versions but works in GCC and MSVC.

Tagging the people involved in the previous issue because it seems very similar:
@shafik
@royjacobson
@erichkeane

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"diverges-from:gccDoes the clang frontend diverge from gcc on this issuediverges-from:msvcDoes the clang frontend diverge from msvc on this issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions