Skip to content

[clang] False positive "-Wunsequenced" for C++20 parenthesized initializer lists #83474

@vapdrs

Description

@vapdrs

Clang 17.0.6 and the latest git/main branch will issue "-Wunsequenced" for the following code sample,

int val = 0;
struct S { int a; int b; };

int paren_list_init[](val++, val++);
int direct_list_init[]{val++, val++};

S paren_list_init_s(val++, val++);
S direct_list_init_s{val++, val++};

for only the C++20 parenthesized initializer lists, even though both are sequenced operations.

$ guix shell clang -- clang -c -o /dev/null -Wunsequenced -std=c++20 test.cpp 
test.cpp:4:26: warning: multiple unsequenced modifications to 'val' [-Wunsequenced]
    4 | int paren_list_init[](val++, val++);
      |                          ^      ~~
test.cpp:7:24: warning: multiple unsequenced modifications to 'val' [-Wunsequenced]
    7 | S paren_list_init_s(val++, val++);
      |                        ^      ~~
2 warnings generated.

I believe this to be a false positive because the C++20 parenthesized initializer lists added in p0960r3 explicitly state that the values and sides effects are explicitly sequenced, and provides the ordering. See C++20 [decl.init]p16.5 and [decl.init]p16.6.2.2, or the latest draft here and here

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 partyfalse-positiveWarning fires when it should not

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions