2009-03-24 10:24:46 +08:00
// RUN: clang-cc -fsyntax-only -verify %s
2007-07-24 01:05:23 +08:00
void f ( int z ) {
while ( z ) {
2007-08-24 02:29:20 +08:00
default : z - - ; // expected-error {{statement not in switch}}
2007-07-24 01:05:23 +08:00
}
}
2007-08-23 13:46:52 +08:00
void foo ( int X ) {
switch ( X ) {
2008-11-24 07:12:31 +08:00
case 42 : ; // expected-note {{previous case}}
2007-08-24 02:29:20 +08:00
case 5000000000LL : // expected-warning {{overflow}}
case 42 : // expected-error {{duplicate case value}}
2007-08-23 13:46:52 +08:00
;
2007-08-24 01:48:14 +08:00
2007-08-24 02:29:20 +08:00
case 100 . . . 99 : ; // expected-warning {{empty case range}}
2008-11-24 07:12:31 +08:00
case 43 : ; // expected-note {{previous case}}
2007-08-24 02:29:20 +08:00
case 43 . . . 45 : ; // expected-error {{duplicate case value}}
2008-11-24 07:12:31 +08:00
case 100 . . . 20000 : ; // expected-note {{previous case}}
2007-08-24 02:29:20 +08:00
case 15000 . . . 40000000 : ; // expected-error {{duplicate case value}}
2007-08-23 13:46:52 +08:00
}
}
2007-08-23 22:29:07 +08:00
void test3 ( void ) {
2007-08-24 02:29:20 +08:00
// empty switch;
2007-08-23 22:29:07 +08:00
switch ( 0 ) ;
}
2008-11-23 05:04:56 +08:00
extern int g ( ) ;
void test4 ( )
{
switch ( 1 ) {
case 0 & & g ( ) :
case 1 | | g ( ) :
break ;
}
switch ( 1 ) {
2008-12-01 10:13:02 +08:00
case g ( ) : / / expected - error { { expression is not an integer constant expression } }
case 0 . . . g ( ) : // expected-error {{expression is not an integer constant expression}}
2008-11-23 05:04:56 +08:00
break ;
}
switch ( 1 ) {
case 0 & & g ( ) . . . 1 | | g ( ) :
break ;
}
2008-11-23 05:50:49 +08:00
switch ( 1 ) {
2008-12-01 10:13:02 +08:00
case g ( ) & & 0 : / / expected - error { { expression is not an integer constant expression } } // expected-note {{subexpression not valid in an integer constant expression}}
2008-11-23 05:50:49 +08:00
break ;
}
switch ( 1 ) {
2008-12-01 10:13:02 +08:00
case 0 . . . g ( ) | | 1 : // expected-error {{expression is not an integer constant expression}} // expected-note {{subexpression not valid in an integer constant expression}}
2008-11-23 05:50:49 +08:00
break ;
}
2008-11-23 05:04:56 +08:00
}
2008-11-24 07:12:31 +08:00
void test5 ( int z ) {
switch ( z ) {
default : // expected-note {{previous case defined here}}
default : // expected-error {{multiple default labels in one switch}}
break ;
}
}