[clang] [llvm] [clang-tools-extra] [clang] Fix false positive -Wmissing-field-initializer for anonymous unions (PR #70829)

Mariya Podchishchaeva via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 14 02:49:45 PST 2023


================
@@ -727,6 +729,44 @@ void InitListChecker::FillInEmptyInitForField(unsigned Init, FieldDecl *Field,
     if (hadError || VerifyOnly) {
       // Do nothing
     } else if (Init < NumInits) {
----------------
Fznamznon wrote:

> Maybe consider changing the L674 condition to an assert(Init < NumInits) and simplify this too?

I'm not sure I understand the suggestion. The condition on L674 looks like:
```
if (Init >= NumInits || !ILE->getInit(Init)) {
```
Even if I only remove `Init >= NumInits`, build of check-clang starts asserting with
```
Assertion `Init < getNumInits() && "Initializer access out of range!"'
```

Removing `!ILE->getInit(Init)` also doesn't seem logical to me since `FillInEmptyInitForField` is called for all fields in a record.

https://github.com/llvm/llvm-project/pull/70829


More information about the cfe-commits mailing list