Bug 23959 - [4.0 Regression] -Wswitch-default reports missing default in a template that has one
Summary: [4.0 Regression] -Wswitch-default reports missing default in a template that ...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.0.1
: P2 normal
Target Milestone: 4.0.3
Assignee: Andrew Pinski
URL: http://gcc.gnu.org/ml/gcc-patches/200...
Keywords: diagnostic, patch
Depends on:
Blocks:
 
Reported: 2005-09-19 02:34 UTC by Roger Libiez
Modified: 2005-10-16 21:24 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work: 3.4.0 4.1.0
Known to fail: 4.0.0 4.0.2
Last reconfirmed: 2005-09-19 02:41:50


Attachments
Preprocessed compiler output (93.49 KB, text/plain)
2005-09-19 02:35 UTC, Roger Libiez
Details
patch which needs testing (352 bytes, patch)
2005-10-15 19:35 UTC, Andrew Pinski
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Roger Libiez 2005-09-19 02:34:22 UTC
-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;
}
Comment 1 Roger Libiez 2005-09-19 02:35:53 UTC
Created attachment 9772 [details]
Preprocessed compiler output

The preprocessed output from the -save-temps option.
Comment 2 Andrew Pinski 2005-09-19 02:41:50 UTC
Confirmed, reduced testcase:
template <typename ArrayType>
void foo( )
{
    int i = 0;

  switch ( i )
  {
  case 9:
  default:
  break;
  }
}
Comment 3 Andrew Pinski 2005-09-19 17:57:12 UTC
: 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).
Comment 4 Andrew Pinski 2005-09-19 17:58:17 UTC
Obviously caused by:
2003-10-30  Richard Henderson  <rth@redhat.com>

        * decl.c (pop_switch): Call c_do_switch_warnings.

Comment 5 Andrew Pinski 2005-10-15 19:12:15 UTC
I wonder if we could get away with only calling c_do_switch_warnings when not processing template.  I will look into that.
Comment 6 Andrew Pinski 2005-10-15 19:35:03 UTC
Created attachment 9989 [details]
patch which needs testing
Comment 7 Andrew Pinski 2005-10-16 14:43:41 UTC
Patch posted:
http://gcc.gnu.org/ml/gcc-patches/2005-10/msg00922.html
Comment 8 Andrew Pinski 2005-10-16 21:12:50 UTC
Fixed at least on the mainline, 4.0 branch version will be committed soon.
Comment 9 GCC Commits 2005-10-16 21:13:17 UTC
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

Comment 10 GCC Commits 2005-10-16 21:23:31 UTC
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

Comment 11 GCC Commits 2005-10-16 21:24:41 UTC
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

Comment 12 Andrew Pinski 2005-10-16 21:24:57 UTC
Fixed.