public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/36839] New: struct with only anonymous unions plus flexible array member
@ 2008-07-15 16:33 rtc at gmx dot de
2008-12-27 20:33 ` [Bug c/36839] " pinskia at gcc dot gnu dot org
` (4 more replies)
0 siblings, 5 replies; 7+ messages in thread
From: rtc at gmx dot de @ 2008-07-15 16:33 UTC (permalink / raw)
To: gcc-bugs
If I declare a struct with only anonymous unions plus a flexible array member,
gcc 4.2.3 complains about "flexible array member in otherwise empty struct"
Only if I add some other object to the struct the error goes away. removing the
flexible array member causes the error to go away, and sizeof reports the
expected size, which means that the struct is by no means "otherwise empty".
Here is an example:
cat > aufbug.c << EOF
#include <stdio.h>
int main(void)
{
struct buggy {
union {
int a;
char *b;
};
#ifdef OTHER_MEMBER
int x;
#endif
#ifdef FLEXIBLE
char rest[];
#endif
};
printf("%zu\n", sizeof (struct buggy));
return 0;
}
EOF
$ rm -f aufbug && make aufbug CFLAGS="-g3 -Wall -O2 -DFLEXIBLE" && ./aufbug
cc -g3 -Wall -O2 -DFLEXIBLE aufbug.c -o aufbug
aufbug.c: In function 'main':
aufbug.c:14: error: flexible array member in otherwise empty struct
make: *** [aufbug] Error 1
$ rm -f aufbug && make aufbug CFLAGS="-g3 -Wall -O2 -DFLEXIBLE -DOTHER_MEMBER"
&& ./aufbug
cc -g3 -Wall -O2 -DFLEXIBLE -DOTHER_MEMBER aufbug.c -o aufbug
8
$ rm -f aufbug && make aufbug CFLAGS="-g3 -Wall -O2" && ./aufbug
cc -g3 -Wall -O2 aufbug.c -o aufbug
4
--
Summary: struct with only anonymous unions plus flexible array
member
Product: gcc
Version: 4.2.3
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: rtc at gmx dot de
GCC build triplet: i486-pc-linux-gnu
GCC host triplet: i486-pc-linux-gnu
GCC target triplet: i486-pc-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36839
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c/36839] struct with only anonymous unions plus flexible array member
2008-07-15 16:33 [Bug c/36839] New: struct with only anonymous unions plus flexible array member rtc at gmx dot de
@ 2008-12-27 20:33 ` pinskia at gcc dot gnu dot org
2008-12-27 20:46 ` pinskia at gcc dot gnu dot org
` (3 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2008-12-27 20:33 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from pinskia at gcc dot gnu dot org 2008-12-27 20:31 -------
else if (!saw_named_field)
{
error ("%Jflexible array member in otherwise empty struct", x);
TREE_TYPE (x) = error_mark_node;
}
Hmm, it explicitly looks for a named field.
--
pinskia at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |pinskia at gcc dot gnu dot
| |org
GCC build triplet|i486-pc-linux-gnu |
GCC host triplet|i486-pc-linux-gnu |
GCC target triplet|i486-pc-linux-gnu |
Keywords| |rejects-valid
Known to fail| |4.0.1 3.3.3 4.1.1 4.3.0
| |4.4.0
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36839
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c/36839] struct with only anonymous unions plus flexible array member
2008-07-15 16:33 [Bug c/36839] New: struct with only anonymous unions plus flexible array member rtc at gmx dot de
2008-12-27 20:33 ` [Bug c/36839] " pinskia at gcc dot gnu dot org
@ 2008-12-27 20:46 ` pinskia at gcc dot gnu dot org
2009-02-27 20:28 ` vegard dot nossum at gmail dot com
` (2 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2008-12-27 20:46 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from pinskia at gcc dot gnu dot org 2008-12-27 20:45 -------
http://gcc.gnu.org/ml/gcc-patches/2001-01/msg00357.html
Hmm, this is on purpose as far as I can tell.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36839
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c/36839] struct with only anonymous unions plus flexible array member
2008-07-15 16:33 [Bug c/36839] New: struct with only anonymous unions plus flexible array member rtc at gmx dot de
2008-12-27 20:33 ` [Bug c/36839] " pinskia at gcc dot gnu dot org
2008-12-27 20:46 ` pinskia at gcc dot gnu dot org
@ 2009-02-27 20:28 ` vegard dot nossum at gmail dot com
2009-02-27 20:32 ` vegard dot nossum at gmail dot com
2009-02-27 20:58 ` joseph at codesourcery dot com
4 siblings, 0 replies; 7+ messages in thread
From: vegard dot nossum at gmail dot com @ 2009-02-27 20:28 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from vegard dot nossum at gmail dot com 2009-02-27 20:27 -------
I'm hitting this as well :-(
[vegard@damson ~/programming 0]
$ cat flexible-array-empty-struct.c
struct x {
union {
int x;
};
int array[];
};
[vegard@damson ~/programming 0]
$ gcc -c flexible-array-empty-struct.c
flexible-array-empty-struct.c:6: error: flexible array member in otherwise
empty struct
[vegard@damson ~/programming 1]
$ gcc -v
Using built-in specs.
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla
--enable-bootstrap --enable-shared --enable-threads=posix
--enable-checking=release --with-system-zlib --enable-__cxa_atexit
--disable-libunwind-exceptions
--enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk
--disable-dssi --enable-plugin
--with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre
--enable-libgcj-multifile --enable-java-maintainer-mode
--with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib
--with-cpu=generic --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.3.2 20081105 (Red Hat 4.3.2-7) (GCC)
--
vegard dot nossum at gmail dot com changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |vegard dot nossum at gmail
| |dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36839
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c/36839] struct with only anonymous unions plus flexible array member
2008-07-15 16:33 [Bug c/36839] New: struct with only anonymous unions plus flexible array member rtc at gmx dot de
` (2 preceding siblings ...)
2009-02-27 20:28 ` vegard dot nossum at gmail dot com
@ 2009-02-27 20:32 ` vegard dot nossum at gmail dot com
2009-02-27 20:58 ` joseph at codesourcery dot com
4 siblings, 0 replies; 7+ messages in thread
From: vegard dot nossum at gmail dot com @ 2009-02-27 20:32 UTC (permalink / raw)
To: gcc-bugs
------- Comment #4 from vegard dot nossum at gmail dot com 2009-02-27 20:32 -------
Workaround:
Install an empty dummy member between the union and the array, like this:
struct x {
union {
int x;
};
int _dummy[0]; // workaround
int array[];
};
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36839
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c/36839] struct with only anonymous unions plus flexible array member
2008-07-15 16:33 [Bug c/36839] New: struct with only anonymous unions plus flexible array member rtc at gmx dot de
` (3 preceding siblings ...)
2009-02-27 20:32 ` vegard dot nossum at gmail dot com
@ 2009-02-27 20:58 ` joseph at codesourcery dot com
4 siblings, 0 replies; 7+ messages in thread
From: joseph at codesourcery dot com @ 2009-02-27 20:58 UTC (permalink / raw)
To: gcc-bugs
------- Comment #5 from joseph at codesourcery dot com 2009-02-27 20:58 -------
Subject: Re: struct with only anonymous unions plus flexible
array member
Anonymous unions are outside the scope of C99, so this issue is purely
about what is most useful for GNU C right now.
However, there have been discussions of including some form of anonymous
structs and unions in C1x, and if that goes in we'd want to follow
whatever that may say about whether this is valid (along with other
aspects of anonymous structs/unions - hopefully C1x would follow C++).
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36839
^ permalink raw reply [flat|nested] 7+ messages in thread
* [Bug c/36839] struct with only anonymous unions plus flexible array member
[not found] <bug-36839-4@http.gcc.gnu.org/bugzilla/>
@ 2014-04-15 20:22 ` mpolacek at gcc dot gnu.org
0 siblings, 0 replies; 7+ messages in thread
From: mpolacek at gcc dot gnu.org @ 2014-04-15 20:22 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=36839
Marek Polacek <mpolacek at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
CC| |mpolacek at gcc dot gnu.org
Resolution|--- |FIXED
Known to fail| |
--- Comment #6 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
The warning is gone.
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2014-04-15 20:22 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-07-15 16:33 [Bug c/36839] New: struct with only anonymous unions plus flexible array member rtc at gmx dot de
2008-12-27 20:33 ` [Bug c/36839] " pinskia at gcc dot gnu dot org
2008-12-27 20:46 ` pinskia at gcc dot gnu dot org
2009-02-27 20:28 ` vegard dot nossum at gmail dot com
2009-02-27 20:32 ` vegard dot nossum at gmail dot com
2009-02-27 20:58 ` joseph at codesourcery dot com
[not found] <bug-36839-4@http.gcc.gnu.org/bugzilla/>
2014-04-15 20:22 ` mpolacek 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).