Skip to content

[clang] Missing diagnostic when initializing a member variable using uninitialized member variable #134353

Open
@horenmar

Description

@horenmar

I recently found an -Wreorder adjacent issue that does not get diagnosed. In the test_t struct below, we initialize bar using foo member variable, but because foo is declared after bar, we are reading it before initialization. (this can happen e.g. by reordering the member without noticing the dependency).

struct test_t {
  int bar{ foo + 1 };
  int foo{ 3 };
};

int main() {
    test_t t{};
}

CE link

Ideally this would also be caught under -Wreorder or by -Wuninitialized.

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzer

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions