The following program defines two pointers to unnamed structs containing a flexible array as their sole member. The structs are invalid and are rejected with an error in C mode but silently accepted by G++. $ cat t.C && /build/gcc-trunk-svn/gcc/xgcc -B /build/gcc-trunk-svn/gcc -S -Wall -Wextra -Wpedantic t.C struct { int a[]; } *p; struct S { struct { int a[]; } *q; }; t.C:1:22: warning: ‘p’ defined but not used [-Wunused-variable] struct { int a[]; } *p; ^ Clang produces the following output: t.C:1:14: warning: flexible array member 'a' in otherwise empty struct is a GNU extension [-Wgnu-empty-struct] struct { int a[]; } *p; ^ t.C:1:14: warning: flexible array members are a C99 feature [-Wc99-extensions] t.C:4:16: warning: flexible array member 'a' in otherwise empty struct is a GNU extension [-Wgnu-empty-struct] struct { int a[]; } *q; ^ t.C:4:16: warning: flexible array members are a C99 feature [-Wc99-extensions] t.C:1:22: warning: unused variable 'p' [-Wunused-variable] struct { int a[]; } *p; ^ 5 warnings generated.
gcc now produces at least 1 error in c++ mode: $ /usr/local/bin/gcc -c -S -Wall -Wextra -Wpedantic -xc 72754.cc 72754.cc:1:14: error: flexible array member in a struct with no named members struct { int a[]; } *p; ^ 72754.cc:4:15: error: flexible array member in a struct with no named members struct { int a[]; } *q; ^ $ /usr/local/bin/g++ -c -S -Wall -Wextra -Wpedantic -xc++ 72754.cc 72754.cc:1:16: warning: ISO C++ forbids flexible array member ‘a’ [-Wpedantic] struct { int a[]; } *p; ^ 72754.cc:4:17: warning: ISO C++ forbids flexible array member ‘a’ [-Wpedantic] struct { int a[]; } *q; ^ 72754.cc:4:17: error: flexible array member ‘S::<unnamed struct>::a’ in an otherwise empty ‘struct S’ 72754.cc:1:22: warning: ‘p’ defined but not used [-Wunused-variable] struct { int a[]; } *p; ^ $ /sw/opt/llvm-3.1/bin/clang++ -c -S -Wall -Wextra -pedantic -xc++ 72754.cc 72754.cc:1:14: warning: flexible array member 'a' in otherwise empty struct is a GNU extension [-pedantic,-Wgnu] struct { int a[]; } *p; ^ 72754.cc:4:15: warning: flexible array member 'a' in otherwise empty struct is a GNU extension [-pedantic,-Wgnu] struct { int a[]; } *q; ^ 72754.cc:1:22: warning: unused variable 'p' [-Wunused-variable] struct { int a[]; } *p; ^ 3 warnings generated. $ Any idea when this was half-fixed?
The second case has been diagnosed since r241143 (bug 71912) but the first one is still accepted.
Bug 68489 tracks the failure to reject the corresponding array case.
(In reply to Eric Gallager from comment #1) > gcc now produces at least 1 error in c++ mode: > > $ /usr/local/bin/gcc -c -S -Wall -Wextra -Wpedantic -xc 72754.cc > 72754.cc:1:14: error: flexible array member in a struct with no named members > struct { int a[]; } *p; > ^ > 72754.cc:4:15: error: flexible array member in a struct with no named members > struct { int a[]; } *q; > ^ > $ /usr/local/bin/g++ -c -S -Wall -Wextra -Wpedantic -xc++ 72754.cc > 72754.cc:1:16: warning: ISO C++ forbids flexible array member ‘a’ > [-Wpedantic] > struct { int a[]; } *p; > ^ > 72754.cc:4:17: warning: ISO C++ forbids flexible array member ‘a’ > [-Wpedantic] > struct { int a[]; } *q; > ^ > 72754.cc:4:17: error: flexible array member ‘S::<unnamed struct>::a’ in an > otherwise empty ‘struct S’ > 72754.cc:1:22: warning: ‘p’ defined but not used [-Wunused-variable] > struct { int a[]; } *p; > ^ > $ /sw/opt/llvm-3.1/bin/clang++ -c -S -Wall -Wextra -pedantic -xc++ 72754.cc > 72754.cc:1:14: warning: flexible array member 'a' in otherwise empty struct > is a GNU extension [-pedantic,-Wgnu] > struct { int a[]; } *p; > ^ > 72754.cc:4:15: warning: flexible array member 'a' in otherwise empty struct > is a GNU extension [-pedantic,-Wgnu] > struct { int a[]; } *q; > ^ > 72754.cc:1:22: warning: unused variable 'p' [-Wunused-variable] > struct { int a[]; } *p; > ^ > 3 warnings generated. > $ > Let me update the comparison output for clang to a newer version of it (6): $ clang++ -c -S -Wall -Wextra -pedantic -xc++ 72754.cc 72754.cc:1:14: warning: flexible array member 'a' in otherwise empty struct is a GNU extension [-Wgnu-empty-struct] struct { int a[]; } *p; ^ 72754.cc:1:14: warning: flexible array members are a C99 feature [-Wc99-extensions] 72754.cc:4:15: warning: flexible array member 'a' in otherwise empty struct is a GNU extension [-Wgnu-empty-struct] struct { int a[]; } *q; ^ 72754.cc:4:15: warning: flexible array members are a C99 feature [-Wc99-extensions] 72754.cc:1:22: warning: unused variable 'p' [-Wunused-variable] struct { int a[]; } *p; ^ 5 warnings generated. $ (In reply to Martin Sebor from comment #2) > The second case has been diagnosed since r241143 (bug 71912) but the first > one is still accepted. Guess I should mark this as confirmed then.