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

Kees Cook via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 8 11:29:30 PST 2024


kees wrote:

> > I didn't do this because it seemed like this would change a lot of existing test cases
> 
> Can you give some examples of tests that would fail? If we have tests checking that these fail, then perhaps those tests should add `-Werror=pedantic` so that they can continue to fail.

I think I accidentally exaggerated; there were only a couple I found:

clang/test/Sema/flexible-array-in-union.c
clang/test/Sema/transparent-union.c

But sure, I would be fine moving this to pedantic mode, and I'll see if anything else pops up. Should I update this PR or create a new one?

> Weirder, clang and msvc already support this, but only in C++ mode! msvc supports this in C mode! GCC does not support this in either!
> 
> C++ mode: https://godbolt.org/z/esjnE7bnY
> C mode: https://godbolt.org/z/hGE9dhjE1

Right, AIUI, C++ has more strict rules about not allowing 0-sized objects (e.g. "struct { } __empty;" in C++ has a sizeof() == 1), which ends up affecting some of the syntax sanity checking.


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


More information about the cfe-commits mailing list