Bug 25181 - [3.4 Regression] wrong "will never be executed" warning in switch - case block
Summary: [3.4 Regression] wrong "will never be executed" warning in switch - case block
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 3.4.4
: P3 normal
Target Milestone: 4.0.0
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2005-11-30 15:52 UTC by Oliver Stoeneberg
Modified: 2006-03-01 05:01 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work: 3.0.4 4.0.0 4.1.0 4.2.0
Known to fail: 3.3.3 3.4.0
Last reconfirmed: 2005-11-30 16:11:44


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Oliver Stoeneberg 2005-11-30 15:52:57 UTC
The following code will report this:

C:\Dev-Cpp\Projects\test-stlport\main_18.cpp In function `int test_18()': 
13 C:\Dev-Cpp\Projects\test-stlport\main_18.cpp [Warning] will never be executed 

extern int abort();

int test_18()
{
 	int type;
	switch (type)
	{
	case 1:
		int ret = abort();
		if (ret != 0)
			return 2;

		break;

	case 3:
		break;

	default:			
		return 1;
	}
	
	return 0;
}
If you remove "case 3" or "default" the warning will go away.

I already reported something similar under bug 24968.

C:\MinGW_3.4.4\bin>gcc -v
Reading specs from ../lib/gcc/mingw32/3.4.4/specs
Configured with: ../gcc/configure --with-gcc --with-gnu-ld --with-gnu-as --host=
mingw32 --target=mingw32 --prefix=/mingw --enable-threads --disable-nls --enable
-languages=c,c++,f77,ada,objc,java --disable-win32-registry --disable-shared --e
nable-sjlj-exceptions --enable-libgcj --disable-java-awt --without-x --enable-ja
va-gc=boehm --disable-libgcj-debug --enable-interpreter --enable-hash-synchroniz
ation --enable-libstdcxx-debug
Thread model: win32
gcc version 3.4.4 (mingw special)
Comment 1 Andrew Pinski 2005-11-30 16:08:59 UTC
This is invalid code:
t.cc: In function ‘int test_18()’:
t.cc:15: error: jump to case label
t.cc:9: error:   crosses initialization of ‘int ret’
t.cc:18: error: jump to case label
t.cc:9: error:   crosses initialization of ‘int ret’

We should reject this.
Comment 2 Andrew Pinski 2005-11-30 16:11:44 UTC
(In reply to comment #1)
> We should reject this.
But that is a different bug.
Anyways fixing up the code to be legal code:
extern int abort();

int test_18()
{
        int type;
        switch (type)
        {
        case 1:
 {               int ret = abort();
                if (ret != 0)
                        return 2;

                break;}

        case 3:
                break;

        default:
                return 1;
        }

        return 0;
}
---

We only warn for 3.4.x and below except 3.0.4 works so this is only a 3.4 regression.
Comment 3 Oliver Stoeneberg 2005-11-30 20:38:58 UTC
I forgot to meintion, that this happens with C and C++, so I guess it's a middle-end bug!?
Comment 4 Gabriel Dos Reis 2005-11-30 22:23:43 UTC
Subject: Re:  [3.4 Regression] wrong "will never be executed" warning in switch - case block

"oliverst at online dot de" <gcc-bugzilla@gcc.gnu.org> writes:

| I forgot to meintion, that this happens with C and C++, so I guess it's a
| middle-end bug!?

Most probably.

-- Gaby
Comment 5 Oliver Stoeneberg 2005-12-01 12:32:08 UTC
(In reply to comment #1)
> This is invalid code:
> t.cc: In function ‘int test_18()’:
> t.cc:15: error: jump to case label
> t.cc:9: error:   crosses initialization of ‘int ret’
> t.cc:18: error: jump to case label
> t.cc:9: error:   crosses initialization of ‘int ret’
> 
> We should reject this.
> 

Will you create a bug report for this or is there already one filed?

I just tried it with GCC 4.0.2 (downloaded it from http://www.thisiscool.com/gcc_mingw.htm) and the code is still accepted.

C:\MinGW_4.0.2\bin>gcc -v
Using built-in specs.
Target: i686-pc-mingw32
Configured with: /datal/gcc/gcc/configure --prefix=/datal/gcc/build/wingcc --bui
ld=i686-pc-linux-gnu --host=i686-pc-mingw32 --target=i686-pc-mingw32 --enable-la
nguages=c,c++,java --with-gcc --with-gnu-as --with-gnu-ld --with-as=/datal/gcc/b
uild/crossgcc/bin/i686-pc-mingw32-as --with-ld=/datal/gcc/build/crossgcc/bin/i68
6-pc-mingw32-ld --enable-threads=win32 --disable-nls --disable-win32-registry --
disable-shared --disable-debug --without-newlib --enable-libgcj --disable-java-a
wt --without-x --enable-java-gc=boehm --disable-libgcj-debug --enable-interprete
r --enable-hash-synchronization --enable-sjlj-exceptions --enable-libgcj-multifi
le --enable-libgcj-mingw-osapi=ansi
Thread model: win32
gcc version 4.0.2
Comment 6 Gabriel Dos Reis 2006-03-01 05:01:50 UTC
Fixed in 4.0.0 and up.