[clang] [Clang][Sema]: Allow flexible arrays in unions and alone in structs (PR #84428)

Eli Friedman via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 14 14:40:53 PDT 2024


efriedma-quic wrote:

The primary problem with allowing flexible arrays alone in structs/unions is that you end up with a zero-size type.  This leads to weird semantic issues because standard C/C++ doesn't have any provision for zero-size types: pointer arithmetic, struct layout, and initialization aren't well-defined when zero-size types are involved.  Because we support zero-length arrays/empty structs as an extension, we have some solution for some of these cases, but some of the edge cases just explode.  (And there's no guidance from the standard because the standard doesn't allow this in the first place.)

Something like `union U { int x, y[]; };` doesn't run into those issues, though; the expected semantics are pretty unambigious.

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


More information about the cfe-commits mailing list