gcc/gcc/testsuite/gcc.dg/switch-warn-1.c
Marek Polacek a7dc5980e9 re PR c/49859 (gcc could warn about statements between "switch" and first "case")
PR c/49859
	* common.opt (Wswitch-unreachable): New option.
	* doc/invoke.texi: Document -Wswitch-unreachable.
	* gimplify.c (gimplify_switch_expr): Implement the -Wswitch-unreachable
	warning.

	* c-c++-common/Wswitch-unreachable-1.c: New test.
	* gcc.dg/Wswitch-unreachable-1.c: New test.
	* c-c++-common/goacc/sb-2.c (void foo): Add dg-warning.
	* g++.dg/cpp0x/lambda/lambda-switch.C (main): Likewise.
	* g++.dg/gomp/block-10.C: Likewise.
	* gcc.dg/gomp/block-10.c: Likewise.
	* g++.dg/gomp/block-9.C: Likewise.
	* gcc.dg/gomp/block-9.c: Likewise.
	* g++.dg/gomp/target-1.C: Likewise.
	* g++.dg/gomp/target-2.C: Likewise.
	* gcc.dg/gomp/target-1.c: Likewise.
	* gcc.dg/gomp/target-2.c: Likewise. 
	* g++.dg/gomp/taskgroup-1.C: Likewise.
	* gcc.dg/gomp/taskgroup-1.c: Likewise.
	* gcc.dg/gomp/teams-1.c: Likewise.
	* g++.dg/gomp/teams-1.C: Likewise.
	* g++.dg/overload/error3.C: Likewise.
	* g++.dg/tm/jump1.C: Likewise.
	* g++.dg/torture/pr40335.C: Likewise.
	* gcc.dg/c99-vla-jump-5.c: Likewise.
	* gcc.dg/switch-warn-1.c: Likewise.
	* gcc.dg/Wjump-misses-init-1.c: Use -Wno-switch-unreachable.
	* gcc.dg/nested-func-1.c: Likewise.
	* gcc.dg/pr67784-4.c: Likewise.

From-SVN: r236597
2016-05-23 15:37:09 +00:00

48 lines
1.0 KiB
C

/* { dg-do run } */
/* { dg-options "-O0" } */
extern void abort (void);
extern void exit (int);
/* Check that out-of-bounds case warnings work in the case that the
testing expression is promoted. */
int
foo1 (unsigned char i)
{
switch (i)
{
case -1: /* { dg-warning "case label value is less than minimum value for type|statement will never be executed" } */
return 1;
case 256: /* { dg-warning "case label value exceeds maximum value for type" } */
return 2;
default:
return 3;
}
}
/* Like above, but for case ranges that need to be satured. */
int
foo2 (unsigned char i)
{
switch (i)
{
case -1 ... 1: /* { dg-warning "lower value in case label range less than minimum value for type" } */
return 1;
case 254 ... 256: /* { dg-warning "upper value in case label range exceeds maximum value for type" } */
return 2;
default:
return 3;
}
}
int
main (void)
{
if (foo1 (10) != 3)
abort ();
if (foo2 (10) != 3)
abort ();
exit (0);
}