llvm / llvm/llvm-project

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

Open
#162,658 1 comment 0 reactions 0 assignees View on GitHub
clang:diagnostics confirmed
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

```cpp
struct A
{
int a;
};

A a{
.a = 10,
.a = 20,
};
```
This correctly errors with `-std=c++20 -pedantic-errors`:
```console
:8:10: error: initializer overrides prior initialization of this subobject [-Werror,-Winitializer-overrides]
8 | .a = 20,
| ^~
: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:
```console
:8:10: warning: initializer overrides prior initialization of this subobject [-Winitializer-overrides]
8 | .a = 20,
| ^~
: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`.

Contributor guide

Open the contributing guide

Research direction

Start by compiling the provided C++ snippet with the three flag combinations shown: -std=c++20 -pedantic-errors, with -Wextra, and without it. Trace how -Winitializer-overrides is classified under these options; done means the duplicate designated initializer remains an error whenever -pedantic-errors is present, including with -Wextra.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.