public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/94132] New: Valid usage of flexible array member failing to compile
@ 2020-03-11 2:59 amir.ahmed.ansari at outlook dot com
2020-03-11 3:32 ` [Bug c++/94132] " pinskia at gcc dot gnu.org
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: amir.ahmed.ansari at outlook dot com @ 2020-03-11 2:59 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94132
Bug ID: 94132
Summary: Valid usage of flexible array member failing to
compile
Product: gcc
Version: 10.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: amir.ahmed.ansari at outlook dot com
Target Milestone: ---
Until gcc 9.2.0, the following usage was correct:
struct S {
int size;
int data[];
};
struct {
S s;
int data[16];
} var;
>From 9.2.1 onwards, this no longer compiles because the checking has gotten
stricter:
<source>:3:9: error: flexible array member 'S::data' not at end of
'struct<unnamed>'
3 | int data[];
| ^~~~
<source>:8:9: note: next member 'int <unnamed struct>::data [16]' declared here
8 | int data[16];
Funnily, the following workaround circumvents the check:
struct {
union {
struct {
S s;
int data[16];
};
};
} var;
Can we make this check more robust so valid usage isn't rejected? I will leave
it up to the experts to find the solution, but it would be easy for me to use
an attribute such as [[space_follows]] to tell the compiler that valid space
follows this member.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/94132] Valid usage of flexible array member failing to compile
2020-03-11 2:59 [Bug c++/94132] New: Valid usage of flexible array member failing to compile amir.ahmed.ansari at outlook dot com
@ 2020-03-11 3:32 ` pinskia at gcc dot gnu.org
2020-03-11 3:38 ` amir.ahmed.ansari at outlook dot com
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2020-03-11 3:32 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94132
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
>Can we make this check more robust so valid usage isn't rejected?
Why do you think it is valid?
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/94132] Valid usage of flexible array member failing to compile
2020-03-11 2:59 [Bug c++/94132] New: Valid usage of flexible array member failing to compile amir.ahmed.ansari at outlook dot com
2020-03-11 3:32 ` [Bug c++/94132] " pinskia at gcc dot gnu.org
@ 2020-03-11 3:38 ` amir.ahmed.ansari at outlook dot com
2020-03-11 8:09 ` rguenth at gcc dot gnu.org
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: amir.ahmed.ansari at outlook dot com @ 2020-03-11 3:38 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94132
--- Comment #2 from Amir Ansari <amir.ahmed.ansari at outlook dot com> ---
(In reply to Andrew Pinski from comment #1)
> >Can we make this check more robust so valid usage isn't rejected?
>
> Why do you think it is valid?
Because I know the flexible array member data isn't dangling. I have allocated
space immediately following the member that I would like to use. It has been
working perfectly in previous versions. I understand there could be alignment
concerns and if that is the case I am happy to declare it packed. Finally, the
workaround gives the same outcome by typing some more code.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/94132] Valid usage of flexible array member failing to compile
2020-03-11 2:59 [Bug c++/94132] New: Valid usage of flexible array member failing to compile amir.ahmed.ansari at outlook dot com
2020-03-11 3:32 ` [Bug c++/94132] " pinskia at gcc dot gnu.org
2020-03-11 3:38 ` amir.ahmed.ansari at outlook dot com
@ 2020-03-11 8:09 ` rguenth at gcc dot gnu.org
2020-03-11 11:13 ` redi at gcc dot gnu.org
2020-03-11 14:47 ` msebor at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2020-03-11 8:09 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94132
Richard Biener <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |msebor at gcc dot gnu.org
--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
I guess at _least_ [[no_unique_address]] would be needed but then who knows
how exactly previous behavior was in this regard?
Martin, you tightened the checks (I agree to those), any input?
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/94132] Valid usage of flexible array member failing to compile
2020-03-11 2:59 [Bug c++/94132] New: Valid usage of flexible array member failing to compile amir.ahmed.ansari at outlook dot com
` (2 preceding siblings ...)
2020-03-11 8:09 ` rguenth at gcc dot gnu.org
@ 2020-03-11 11:13 ` redi at gcc dot gnu.org
2020-03-11 14:47 ` msebor at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2020-03-11 11:13 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94132
--- Comment #4 from Jonathan Wakely <redi at gcc dot gnu.org> ---
https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html
"A structure containing a flexible array member, or a union containing such a
structure (possibly recursively), may not be a member of a structure or an
element of an array. (However, these uses are permitted by GCC as extensions.)"
The C++ compiler implements the stricter rule from ISO C, not the extension.
(In reply to Amir Ansari from comment #2)
> Because I know the flexible array member data isn't dangling. I have
> allocated space immediately following the member that I would like to use.
That's not how you're supposed to do it. You're supposed to dynamically
allocate space for the struct and space after it, not place it inside a larger
structute.
> It has been working perfectly in previous versions.
I'd say it's actually been undefined because G++ allowed pretty much any
nonsense in terms of flexible array members.
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug c++/94132] Valid usage of flexible array member failing to compile
2020-03-11 2:59 [Bug c++/94132] New: Valid usage of flexible array member failing to compile amir.ahmed.ansari at outlook dot com
` (3 preceding siblings ...)
2020-03-11 11:13 ` redi at gcc dot gnu.org
@ 2020-03-11 14:47 ` msebor at gcc dot gnu.org
4 siblings, 0 replies; 6+ messages in thread
From: msebor at gcc dot gnu.org @ 2020-03-11 14:47 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94132
Martin Sebor <msebor at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Blocks| |69698
Resolution|--- |INVALID
--- Comment #5 from Martin Sebor <msebor at gcc dot gnu.org> ---
Right, the code is invalid according to the C rules. It's accepted by the C
front end with a pedantic warning. It's intentionally rejected by the C++
front-end which supports fewer of the GCC extensions. The zero-length array
extension can be used in this context instead, though accessing elements of the
zero-length array may be diagnosed. (In both cases, GCC assumes that the array
doesn't overlap other members so accesses to its elements are undefined.)
Referenced Bugs:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69698
[Bug 69698] [meta-bug] flexible array members
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2020-03-11 14:47 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-11 2:59 [Bug c++/94132] New: Valid usage of flexible array member failing to compile amir.ahmed.ansari at outlook dot com
2020-03-11 3:32 ` [Bug c++/94132] " pinskia at gcc dot gnu.org
2020-03-11 3:38 ` amir.ahmed.ansari at outlook dot com
2020-03-11 8:09 ` rguenth at gcc dot gnu.org
2020-03-11 11:13 ` redi at gcc dot gnu.org
2020-03-11 14:47 ` 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).