Skip to content

Wrong warning generated (gcc works OK) #146377

Open
@socketpair

Description

@socketpair

The following code is pretty correct, but Clang emits warning. I consider it a bug.

struct X {
    int x_field{};
};

struct Y {
    template <class>
    Y() : y_field(x.x_field) {}

    X x;
    int y_field;
};

https://godbolt.org/z/GM3Yjs93a

x86-64 clang (trunk) -O3 -std=c++20 -Wall -Wextra :

<source>:7:19: warning: field 'x' is uninitialized when used here [-Wuninitialized]
    7 |     Y() : y_field(x.x_field) {}

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerconfirmedVerified by a second party

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions