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

Richard Smith via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 22 11:27:12 PST 2023


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

Hm, right, we still call this with `Init >= NumInits` when in `VerifyOnly` mode (but *only* in that mode).

My concern here is that we're only warning in the `Init < NumInits` case, which is in principle wrong -- we should warn regardless of whether `Init < NumInits`. But in fact, the caller always resizes the `InitListExpr` so that `Init >= NumInits` whenever we're not in `VerifyOnly` mode, so I think this is probably not *actually* wrong, but it still *looks* wrong.

To make it not look wrong, I think we should remove all the dead code here: instead of checking whether `Init < NumInits` in non-`VerifyOnly` mode, we should assert that `Init < NumInits`, and delete the unreachable code that is trying to handle the impossible case: lines 684-685, 704-707, 772-778. Does that make sense?

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


More information about the llvm-commits mailing list