[PATCH] D147626: [clang] Reject flexible array member in a union in C++

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed May 3 13:00:08 PDT 2023


aaron.ballman added a comment.

In D147626#4316535 <https://reviews.llvm.org/D147626#4316535>, @efriedma wrote:

> In D147626#4316212 <https://reviews.llvm.org/D147626#4316212>, @aaron.ballman wrote:
>
>> In D147626#4316190 <https://reviews.llvm.org/D147626#4316190>, @efriedma wrote:
>>
>>>> If there's not indications of this being disruptive on non-MSVC-compatible targets, then we may still be able to get away with rejecting the extension there.
>>>
>>> If we need to have the codepath anyway, there isn't much harm in allowing it on all targets, I think.  There's really only one possible interpretation for the construct.
>>
>> You would think, except the GCC extension differs based on C vs C++: https://godbolt.org/z/E14Yz37To as does the extension in Clang, but differently than GCC: https://godbolt.org/z/zYznaYPf5 and so we'd also have to dig into solving that if we wanted to keep GCC compatibility behavior.
>
> I don't see any unions there?  Declaring a flexible array is separate from flexible array initialization.

Sorry, that was a rather bad think-o -- those examples came from GCC's documentation of FAM extensions (https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html), but you're right, that example is not about declarations but initialization. @Fznamznon had an example: https://godbolt.org/z/jsWjv7svr

> Actually, despite my saying the interpretation for unions is "obvious", it's actually a little more weird than I thought: `union x { short x[]; }; static_assert(sizeof(x)==2);` compiles with msvc.

Well that's... a bit shorter... than I would have expected that union to be. (I'm not apologizing for the pun.)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D147626



More information about the cfe-commits mailing list