From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id BD9493857C71; Fri, 16 Apr 2021 20:18:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BD9493857C71 From: "gcc at behdad dot org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/100124] New: Why is "flexible array member '...' in an otherwise empty '...'" an issue? Date: Fri, 16 Apr 2021 20:18:20 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: unknown X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: gcc at behdad dot org X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 16 Apr 2021 20:18:20 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D100124 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 wi= th 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 memb= er '...' in an otherwise empty '...'". ``` struct UnsignedArray { int array[]; }; ``` I've seen: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D69550 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D71742 which suggests that disallowing flexible arrays in structs that have no oth= er named member is intentional. But I cannot find the reason. Can someone plea= se 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=