https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100124
Bug ID: 100124 Summary: Why is "flexible array member '...' in an otherwise empty '...'" an issue? Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: gcc at behdad dot org Target Milestone: --- Hi, In HarfBuzz we extensively use the Struct Hack [0]. Up until now we've used "array[1]" for that. This upsets ubsan [1]. So I'm looking to replace it with flexible arrays on compilers that support it. However, trying to do that I get error if the flexible-array is the only member. Clang has no issues with it, but gcc gives me: "flexible array member '...' in an otherwise empty '...'". ``` struct UnsignedArray { int array[]; }; ``` I've seen: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69550 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71742 which suggests that disallowing flexible arrays in structs that have no other named member is intentional. But I cannot find the reason. Can someone please help me understand, and suggest a solution here? Note that if I use `int array[0]` instead, then gcc warns everytime in code we access that array with a constexpr value, like `array[0]` when we know it's safe to do. That is, gcc seems to treat `int array[0]` literally, not as a flexible array. Thank you. [0] http://c-faq.com/struct/structhack.html [1] https://github.com/harfbuzz/harfbuzz/issues/2953