In GCC 4.5.0, the -Wc++-compat option prints a warning for anonymous unions in
C code, even though this code is correct C++ and is accepted by G++.

This is a regression from GCC 4.4.

$ gcc-4.5 -Wc++-compat -save-temps -c anon-union.c
anon-union.c:15:2: warning: using ‘({anonymous})’ as both field and typedef
name is invalid in C++

$ g++-4.5 -Wall -save-temps -c anon-union.c
[no error]

$ gcc-4.4 -Wc++-compat -save-temps -c anon-union.c
[no error]

$ cat anon-union.c


typedef enum {
        union_type_1,
        union_type_2
} union_discriminator;


typedef struct {
        union_discriminator discriminator;

        union {
                int type1;
                char* type2;
        };
} struct_with_anon_union;

struct_with_anon_union foo;


$ gcc-4.5 -Wc++-compat -save-temps -v -c anon-union.c
Using built-in specs.
COLLECT_GCC=/home/jonathan/GCC/FSF/bin/gcc-4.5
COLLECT_LTO_WRAPPER=/home/jonathan/GCC/FSF/libexec/gcc/i486-linux-gnu/4.5.0/lto-wrapper
Target: i486-linux-gnu
Configured with: ../gcc-4.5.0/configure
--enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/home/jonathan/GCC/FSF
--enable-shared --enable-multiarch --enable-linker-build-id --with-system-zlib
--without-included-gettext --enable-threads=posix
--with-gxx-include-dir=/home/jonathan/GCC/FSF/include/c++/4.5
--program-suffix=-4.5 --enable-nls --enable-clocale=gnu
--enable-libstdcxx-debug --enable-objc-gc --enable-targets=all --disable-werror
--with-arch-32=i486 --with-tune=generic --enable-checking=release
--build=i486-linux-gnu --host=i486-linux-gnu --target=i486-linux-gnu
Thread model: posix
gcc version 4.5.0 (GCC)
COLLECT_GCC_OPTIONS='-Wc++-compat' '-save-temps' '-v' '-c' '-mtune=generic'
'-march=i486'
 /home/jonathan/GCC/FSF/libexec/gcc/i486-linux-gnu/4.5.0/cc1 -E -quiet -v
anon-union.c -mtune=generic -march=i486 -Wc++-compat -fpch-preprocess -o
anon-union.i
ignoring nonexistent directory
"/home/jonathan/GCC/FSF/lib/gcc/i486-linux-gnu/4.5.0/../../../../i486-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/include
 /home/jonathan/GCC/FSF/include
 /home/jonathan/GCC/FSF/lib/gcc/i486-linux-gnu/4.5.0/include
 /home/jonathan/GCC/FSF/lib/gcc/i486-linux-gnu/4.5.0/include-fixed
 /usr/include
End of search list.
COLLECT_GCC_OPTIONS='-Wc++-compat' '-save-temps' '-v' '-c' '-mtune=generic'
'-march=i486'
 /home/jonathan/GCC/FSF/libexec/gcc/i486-linux-gnu/4.5.0/cc1 -fpreprocessed
anon-union.i -quiet -dumpbase anon-union.c -mtune=generic -march=i486 -auxbase
anon-union -Wc++-compat -version -o anon-union.s
GNU C (GCC) version 4.5.0 (i486-linux-gnu)
        compiled by GNU C version 4.5.0, GMP version 4.3.2, MPFR version 2.4.2,
MPC version 0.8.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
GNU C (GCC) version 4.5.0 (i486-linux-gnu)
        compiled by GNU C version 4.5.0, GMP version 4.3.2, MPFR version 2.4.2,
MPC version 0.8.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: cef540cf95bd7b1d645fe58566717d69
anon-union.c:15:2: warning: using ‘({anonymous})’ as both field and typedef
name is invalid in C++
COLLECT_GCC_OPTIONS='-Wc++-compat' '-save-temps' '-v' '-c' '-mtune=generic'
'-march=i486'
 as -V -Qy --32 -o anon-union.o anon-union.s
GNU assembler version 2.20 (i486-linux-gnu) using BFD version (GNU Binutils for
Ubuntu) 2.20
COMPILER_PATH=/home/jonathan/GCC/FSF/libexec/gcc/i486-linux-gnu/4.5.0/:/home/jonathan/GCC/FSF/libexec/gcc/i486-linux-gnu/4.5.0/:/home/jonathan/GCC/FSF/libexec/gcc/i486-linux-gnu/:/home/jonathan/GCC/FSF/lib/gcc/i486-linux-gnu/4.5.0/:/home/jonathan/GCC/FSF/lib/gcc/i486-linux-gnu/
LIBRARY_PATH=/home/jonathan/GCC/FSF/lib/gcc/i486-linux-gnu/4.5.0/:/home/jonathan/GCC/FSF/lib/gcc/i486-linux-gnu/4.5.0/../../../../lib/:/lib/../lib/:/usr/lib/../lib/:/home/jonathan/GCC/FSF/lib/gcc/i486-linux-gnu/4.5.0/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-Wc++-compat' '-save-temps' '-v' '-c' '-mtune=generic'
'-march=i486'


-- 
           Summary: -Wc++-compat warns incorrectly for anonymous unions
                    [regression from 4.4]
           Product: gcc
           Version: 4.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: lennox at cs dot columbia dot edu
 GCC build triplet: i486-linux-gnu
  GCC host triplet: i486-linux-gnu
GCC target triplet: i486-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=44772

Reply via email to