public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/100124] New: Why is "flexible array member '...' in an otherwise empty '...'" an issue?
@ 2021-04-16 20:18 gcc at behdad dot org
  2021-04-16 20:50 ` [Bug c++/100124] " pinskia at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: gcc at behdad dot org @ 2021-04-16 20:18 UTC (permalink / raw)
  To: gcc-bugs

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

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2021-04-26 22:26 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-16 20:18 [Bug c/100124] New: Why is "flexible array member '...' in an otherwise empty '...'" an issue? gcc at behdad dot org
2021-04-16 20:50 ` [Bug c++/100124] " pinskia at gcc dot gnu.org
2021-04-16 21:02 ` jakub at gcc dot gnu.org
2021-04-17  0:03 ` msebor at gcc dot gnu.org
2021-04-17  0:51 ` pinskia at gcc dot gnu.org
2021-04-17 21:13 ` msebor at gcc dot gnu.org
2021-04-20 19:32 ` gcc at behdad dot org
2021-04-20 20:30 ` pinskia at gcc dot gnu.org
2021-04-20 22:16 ` gcc at behdad dot org
2021-04-26 22:26 ` msebor at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).