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

            Bug ID: 60184
           Summary: g++ does not allow static members of named unions
           Product: gcc
           Version: 4.6.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: d0sboots at gmail dot com

cat > test.cc <<EOF
union Test {
  static constexpr int kConstant = 10;
};
EOF
g++ --std=c++0x -c -o test.o test.cc

produces:
test.cc:2:36: error: 'Test::kConstant' may not be static because it is a member
of a union

However, this is correct according to my reading of the standard, as well as
the folks here:
http://stackoverflow.com/questions/15996333/does-c11-allow-non-anonymous-unions-to-contain-static-data-members
It is also allowed by clang.

9/5 : "A union is a class defined with the class-key union; it holds only one
data member at a time"

Section 9.4, in general, describes static members. It places no restrictions on
static members in union-type classes.

9.5/1: "In a union, at most one of the non-static data members can be active at
any time, that is, the value of at most one of the non-static data members can
be stored in a union at any time."
There is no reason to specifically call out "non-static data members" unless
static data members can exist.

9.5/5: "The member-specification of an anonymous union shall only define
non-static data members."
This only applies to anonymous unions. That this is specifically called out for
anonymous unions implies that it *is* allowed in general.

gcc -v:
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.6/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro
4.6.3-1ubuntu5' --with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs
--enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr
--program-suffix=-4.6 --enable-shared --enable-linker-build-id
--with-system-zlib --libexecdir=/usr/lib --without-included-gettext
--enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.6
--libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu
--enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object
--enable-plugin --enable-objc-gc --disable-werror --with-arch-32=i686
--with-tune=generic --enable-checking=release --build=x86_64-linux-gnu
--host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5)

Reply via email to