-Wswitch default warning flag is producing a warning message saying that a template does not have a default case even though it does. GCC version specs: Using built-in specs. Target: i386-redhat-linux Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-libgcj-multifile --enable-languages=c,c++,objc,java,f95,ada --enable-java-awt=gtk --with-java-home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre --host=i386-redhat-linux Thread model: posix gcc version 4.0.1 20050727 (Red Hat 4.0.1-5) Installed via RPM package from Fedora Core 4 Command line: g++ -o test test.c -Wswitch-default -Wall --pedantic Compiler output: test.c: In function 'void foo(ArrayType*)': test.c:12: warning: switch missing default case Detailed output: g++ -v -save-temps -Wswitch-default -Wall --pedantic -o test test.c Using built-in specs. Target: i386-redhat-linux Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-libgcj-multifile --enable-languages=c,c++,objc,java,f95,ada --enable-java-awt=gtk --with-java-home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre --host=i386-redhat-linux Thread model: posix gcc version 4.0.1 20050727 (Red Hat 4.0.1-5) /usr/libexec/gcc/i386-redhat-linux/4.0.1/cc1plus -E -quiet -v -D_GNU_SOURCE test.c -Wswitch-default -Wall -pedantic -fpch-preprocess -o test.ii ignoring nonexistent directory "/usr/lib/gcc/i386-redhat-linux/4.0.1/../../../../i386-redhat-linux/include" #include "..." search starts here: #include <...> search starts here: /usr/lib/gcc/i386-redhat-linux/4.0.1/../../../../include/c++/4.0.1 /usr/lib/gcc/i386-redhat-linux/4.0.1/../../../../include/c++/4.0.1/i386-redhat-linux /usr/lib/gcc/i386-redhat-linux/4.0.1/../../../../include/c++/4.0.1/backward /usr/local/include /usr/lib/gcc/i386-redhat-linux/4.0.1/include /usr/include End of search list. /usr/libexec/gcc/i386-redhat-linux/4.0.1/cc1plus -fpreprocessed test.ii -quiet -dumpbase test.c -auxbase test -Wswitch-default -Wall -pedantic -version -o test.s GNU C++ version 4.0.1 20050727 (Red Hat 4.0.1-5) (i386-redhat-linux) compiled by GNU C version 4.0.1 20050727 (Red Hat 4.0.1-5). GGC heuristics: --param ggc-min-expand=81 --param ggc-min-heapsize=96921 test.c: In function 'void foo(ArrayType*)': test.c:12: warning: switch missing default case as -V -Qy -o test.o test.s GNU assembler version 2.15.94.0.2.2 (i386-redhat-linux) using BFD version 2.15.94.0.2.2 20041220 /usr/libexec/gcc/i386-redhat-linux/4.0.1/collect2 --eh-frame-hdr -m elf_i386 -dynamic-linker /lib/ld-linux.so.2 -o test /usr/lib/gcc/i386-redhat-linux/4.0.1/../../../crt1.o /usr/lib/gcc/i386-redhat-linux/4.0.1/../../../crti.o /usr/lib/gcc/i386-redhat-linux/4.0.1/crtbegin.o -L/usr/lib/gcc/i386-redhat-linux/4.0.1 -L/usr/lib/gcc/i386-redhat-linux/4.0.1 -L/usr/lib/gcc/i386-redhat-linux/4.0.1/../../.. test.o -lstdc++ -lm -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/lib/gcc/i386-redhat-linux/4.0.1/crtend.o /usr/lib/gcc/i386-redhat-linux/4.0.1/../../../crtn.o Testcase code: #include <iostream> using namespace std; template <typename ArrayType> void foo( ArrayType * arr ) { int i = 0; for ( ;; ) { switch ( arr[i] ) { default: cout << arr[i] << endl; break; case 1: case 2: case 3: case 4: case 5: case 6: case 7: case 8: case 9: cout << "woot" << endl; continue; } i++; } } int main() { int arr[10] = {1,2,3,4,5,6,7,8,9,10}; foo<int>(arr); return 0; }
Created attachment 9772 [details] Preprocessed compiler output The preprocessed output from the -save-temps option.
Confirmed, reduced testcase: template <typename ArrayType> void foo( ) { int i = 0; switch ( i ) { case 9: default: break; } }
: Search converges between 2004-05-11-trunk (#454) and 2004-05-14-trunk (#455). : Search converges between 2003-10-30-ssa (#120) and 2003-10-31-ssa (#121).
Obviously caused by: 2003-10-30 Richard Henderson <rth@redhat.com> * decl.c (pop_switch): Call c_do_switch_warnings.
I wonder if we could get away with only calling c_do_switch_warnings when not processing template. I will look into that.
Created attachment 9989 [details] patch which needs testing
Patch posted: http://gcc.gnu.org/ml/gcc-patches/2005-10/msg00922.html
Fixed at least on the mainline, 4.0 branch version will be committed soon.
Subject: Bug 23959 CVSROOT: /cvs/gcc Module name: gcc Changes by: pinskia@gcc.gnu.org 2005-10-16 21:13:11 Modified files: gcc/cp : ChangeLog decl.c gcc/testsuite : ChangeLog Added files: gcc/testsuite/g++.dg/warn: Wswitch-default-1.C Wswitch-default-2.C Log message: 2005-10-16 Andrew Pinski <pinskia@physics.uc.edu> PR c++/23959 * decl.c (pop_switch): Only call c_do_switch_warnings when not processing templates. 2005-10-16 Andrew Pinski <pinskia@physics.uc.edu> PR c++/23959 * g++.dg/warn/Wswitch-default-1.C: New test. * g++.dg/warn/Wswitch-default-2.C: New test. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&r1=1.4936&r2=1.4937 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/decl.c.diff?cvsroot=gcc&r1=1.1435&r2=1.1436 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.6199&r2=1.6200 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/warn/Wswitch-default-1.C.diff?cvsroot=gcc&r1=NONE&r2=1.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/warn/Wswitch-default-2.C.diff?cvsroot=gcc&r1=NONE&r2=1.1
Subject: Bug 23959 CVSROOT: /cvs/gcc Module name: gcc Branch: gcc-4_0-branch Changes by: pinskia@gcc.gnu.org 2005-10-16 21:23:26 Modified files: gcc/cp : ChangeLog decl.c gcc/testsuite : ChangeLog Log message: 2005-10-16 Andrew Pinski <pinskia@physics.uc.edu> PR c++/23959 * decl.c (pop_switch): Only call c_do_switch_warnings when not processing templates. 2005-10-16 Andrew Pinski <pinskia@physics.uc.edu> PR c++/23959 * g++.dg/warn/Wswitch-default-1.C: New test. * g++.dg/warn/Wswitch-default-2.C: New test. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.4648.2.136&r2=1.4648.2.137 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/decl.c.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.1371.2.27&r2=1.1371.2.28 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=1.5084.2.459&r2=1.5084.2.460
Subject: Bug 23959 CVSROOT: /cvs/gcc Module name: gcc Branch: gcc-4_0-branch Changes by: pinskia@gcc.gnu.org 2005-10-16 21:24:37 Added files: gcc/testsuite/g++.dg/warn: Wswitch-default-1.C Wswitch-default-2.C Log message: 2005-10-16 Andrew Pinski <pinskia@physics.uc.edu> PR c++/23959 * decl.c (pop_switch): Only call c_do_switch_warnings when not processing templates. 2005-10-16 Andrew Pinski <pinskia@physics.uc.edu> PR c++/23959 * g++.dg/warn/Wswitch-default-1.C: New test. * g++.dg/warn/Wswitch-default-2.C: New test. Patches: http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/warn/Wswitch-default-1.C.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=NONE&r2=1.1.2.1 http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/warn/Wswitch-default-2.C.diff?cvsroot=gcc&only_with_tag=gcc-4_0-branch&r1=NONE&r2=1.1.2.1
Fixed.