http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48780
Summary: [C++0x] scoped enumerations and va_arg (default argument promotions) Product: gcc Version: 4.6.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassig...@gcc.gnu.org ReportedBy: hst...@ca.ibm.com CC: micha...@ca.ibm.com Host: powerpc64-unknown-linux-gnu Target: powerpc64-unknown-linux-gnu In the 2011 FDIS, default argument promotions are defined to leave arguments of scoped enumeration types as-is (without conversion). This appears to be an interaction with old wording and I am not aware of any rationale behind this. For cases where the underlying type has rank lower than that of int, GCC performs the default argument promotions as-if the enumeration is unscoped. This manifests itself as a warning message and a run-time abend. In 5.2.2 [expr.call], If the argument has integral or enumeration type that is subject to the integral promotions (4.5), ..., the value of the argument is converted to the promoted type before the call. These promotions are referred to as the default argument promotions. In 4.5 [conv.prom], integral promotions are not specified to apply to scoped enumerations. ### Self-contained source (a.cpp): typedef __builtin_va_list __gnuc_va_list; typedef __gnuc_va_list va_list; enum struct A : short { X }; void foo(int x, ...) { va_list vl; __builtin_va_start(vl, x); enum A t = __builtin_va_arg(vl, enum A); __builtin_va_end(vl); } int main() { foo(0, A::X); } ### Compiler Invocation: g++ -std=c++0x -Wall -W -pedantic -c a.cpp ### Compiler Output (return code 0): /data/a.cpp: In function 'void foo(int, ...)': /data/a.cpp:9:11: warning: unused variable 't' [-Wunused-variable] /data/a.cpp:9:42: warning: 'A' is promoted to 'int' when passed through '...' [enabled by default] /data/a.cpp:9:42: note: (so you should pass 'int' not 'A' to 'va_arg') /data/a.cpp:9:42: note: if this code is reached, the program will abort ### Run output: Program received signal SIGTRAP, Trace/breakpoint trap. ### g++ -v output: Using built-in specs. Target: powerpc64-unknown-linux-gnu Configured with: ./configure --prefix=/data/gcc --program-suffix=-4.6.0 --disable-libssp --disable-libgcj --enable-version-specific-runtime-libs --with-cpu=default32 --enable-secureplt --with-long-double-128 --enable-shared --enable-__cxa_atexit --enable-threads=posix --enable-languages=c,c++,fortran --with-gmp=/usr/local Thread model: posix gcc version 4.6.0 (GCC)