[PATCH] D157879: [clang] Report missing designated initializers in C++

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 22 06:16:55 PDT 2023


aaron.ballman added a subscriber: jwakely.
aaron.ballman added a comment.

In D157879#4604288 <https://reviews.llvm.org/D157879#4604288>, @phosek wrote:

> Note that there's an ongoing discussion on the GCC bug https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96868 whether `-Wmissing-field-initializers` should apply to both C and C++ or just C.

Thank you for posting this! I'm with @jwakely on this: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96868#c3 -- the warning is for people who want to be told they've not explicitly specified all of the initializers, it is not for telling you "this hasn't been initialized". I think the desire makes as much sense in C++ as it does in C, but this is more of a style warning than a correctness warning.

In D157879#4604471 <https://reviews.llvm.org/D157879#4604471>, @ianloic wrote:

> In D157879#4604233 <https://reviews.llvm.org/D157879#4604233>, @aeubanks wrote:
>
>> ah I thought this was in `-Wall` but it's not
>>
>> the struct is
>>
>>   struct Foo {
>>     const void* buffer;
>>     uint32_t capacity;
>>     uint32_t reserved;
>>   };
>>
>> where `reserved` isn't explicitly initialized. that seems like reasonable code, but I suppose we can just explicitly initialize `reserved` here
>
> FWIW, if this is the specific piece of code that led me to this conversation, that declaration is in a header which at least in theory is supposed to remain compatible with C. It's inside `extern "C" { ... }` even. We can't add explicit initialize `reserved` and keep the definition C comaptible.

Ouch, yeah, that does make it a challenge. But why is `-Wmissing-field-initializers` enabled in the first place for the code? It seems like there are fields you *don't* want explicit initialization for, so perhaps the answer is to disable the diagnostic for those types?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157879/new/

https://reviews.llvm.org/D157879



More information about the cfe-commits mailing list