Skip to content

-Wextra demotes -Winitializer-overrides from error to warning even when -pedantic-errors is present #162658

@HolyBlackCat

Description

@HolyBlackCat
struct A
{
    int a;
};

A a{
    .a = 10,
    .a = 20,
};

This correctly errors with -std=c++20 -pedantic-errors:

<source>:8:10: error: initializer overrides prior initialization of this subobject [-Werror,-Winitializer-overrides]
    8 |     .a = 20,
      |          ^~
<source>:7:10: note: previous initialization is here
    7 |     .a = 10,
      |          ^~

But if I use -std=c++20 -pedantic-errors -Wextra, this instead becomes a warning:

<source>:8:10: warning: initializer overrides prior initialization of this subobject [-Winitializer-overrides]
    8 |     .a = 20,
      |          ^~
<source>:7:10: note: previous initialization is here
    7 |     .a = 10,
      |          ^~

I get the same warning if I use just -std=c++20.

The correct behavior is for this to be an error if -pedantic-errors is present, regardless of -Wextra.

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

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions