2015-10-08 14:31:22 +08:00
// RUN: %clang_cc1 -triple %itanium_abi_triple %s -fsyntax-only -verify -pedantic
2007-08-28 14:15:15 +08:00
enum e { A ,
B = 42LL < < 32 , // expected-warning {{ISO C restricts enumerator values to range of 'int'}}
C = - 4 , D = 12456 } ;
enum f { a = - 2147483648 , b = 2147483647 } ; // ok.
enum g { // too negative
c = - 2147483649 , // expected-warning {{ISO C restricts enumerator values to range of 'int'}}
d = 2147483647 } ;
enum h { e = - 2147483648 , // too pos
2010-02-18 06:40:11 +08:00
f = 2147483648 , // expected-warning {{ISO C restricts enumerator values to range of 'int'}}
i = 0xFFFF0000 // expected-warning {{too large}}
2007-08-28 14:15:15 +08:00
} ;
// minll maxull
enum x // expected-warning {{enumeration values exceed range of largest integer}}
{ y = - 9223372036854775807LL - 1 , // expected-warning {{ISO C restricts enumerator values to range of 'int'}}
z = 9223372036854775808ULL } ; // expected-warning {{ISO C restricts enumerator values to range of 'int'}}
int test ( ) {
return sizeof ( enum e ) ;
}
2009-03-11 07:43:53 +08:00
enum gccForwardEnumExtension ve ; / / expected - warning { { ISO C forbids forward references to ' enum ' types } } \
/ / expected - error { { tentative definition has type ' enum gccForwardEnumExtension ' that is never completed } } \
// expected-note{{forward declaration of 'enum gccForwardEnumExtension'}}
2008-01-17 07:54:22 +08:00
int test2 ( int i )
{
2009-03-11 05:58:27 +08:00
ve + i ; // expected-error{{invalid operands to binary expression}}
2008-01-17 07:54:22 +08:00
}
2008-07-03 11:30:58 +08:00
// PR2020
2008-11-24 07:12:31 +08:00
union u0 ; // expected-note {{previous use is here}}
enum u0 { U0A } ; // expected-error {{use of 'u0' with tag type that does not match previous declaration}}
2008-07-03 11:30:58 +08:00
2008-07-26 07:18:17 +08:00
// rdar://6095136
extern enum some_undefined_enum ve2 ; // expected-warning {{ISO C forbids forward references to 'enum' types}}
void test4 ( ) {
for ( ; ve2 ; ) // expected-error {{statement requires expression of scalar type}}
;
2008-07-26 07:41:08 +08:00
( _Bool ) ve2 ; // expected-error {{arithmetic or pointer type is required}}
2008-07-26 07:18:17 +08:00
2010-09-20 07:03:35 +08:00
for ( ; ; ve2 ) // expected-warning {{expression result unused}}
2008-07-26 07:18:17 +08:00
;
( void ) ve2 ;
2010-09-20 07:03:35 +08:00
ve2 ; // expected-warning {{expression result unused}}
2008-07-26 07:18:17 +08:00
}
2008-07-27 03:15:11 +08:00
// PR2416
2010-05-29 06:43:53 +08:00
enum someenum { } ; // expected-error {{use of empty enum}}
2008-07-27 03:15:11 +08:00
2008-08-08 00:22:45 +08:00
// <rdar://problem/6093889>
2008-11-24 07:12:31 +08:00
enum e0 { // expected-note {{previous definition is here}}
2009-01-20 03:26:10 +08:00
E0 = sizeof ( enum e0 { E1 } ) , // expected-error {{nested redefinition}}
2008-08-08 00:22:45 +08:00
} ;
2008-12-08 10:21:03 +08:00
// PR3173
enum { PR3173A , PR3173B = PR3173A + 50 } ;
2008-12-16 00:32:14 +08:00
// PR2753
void foo ( ) {
enum xpto ; // expected-warning{{ISO C forbids forward references to 'enum' types}}
enum xpto ; // expected-warning{{ISO C forbids forward references to 'enum' types}}
}
2009-01-17 10:55:50 +08:00
// <rdar://problem/6503878>
typedef enum { X = 0 } ; // expected-warning{{typedef requires a name}}
2009-01-20 03:26:10 +08:00
enum NotYetComplete { // expected-note{{definition of 'enum NotYetComplete' is not complete until the closing '}'}}
NYC1 = sizeof ( enum NotYetComplete ) // expected-error{{invalid application of 'sizeof' to an incomplete type 'enum NotYetComplete'}}
} ;
2009-03-07 02:34:03 +08:00
/// PR3688
struct s1 {
enum e1 ( * bar ) ( void ) ; // expected-warning{{ISO C forbids forward references to 'enum' types}}
} ;
enum e1 { YES , NO } ;
static enum e1 badfunc ( struct s1 * q ) {
return q - > bar ( ) ;
}
2010-01-14 06:07:44 +08:00
// Make sure we don't a.k.a. anonymous enums.
typedef enum {
an_enumerator = 20
} an_enum ;
2010-04-10 01:53:29 +08:00
char * s = ( an_enum ) an_enumerator ; // expected-warning {{incompatible integer to pointer conversion initializing 'char *' with an expression of type 'an_enum'}}
2010-02-02 07:36:03 +08:00
// PR4515
enum PR4515 { PR4515a = 1u , PR4515b = ( PR4515a - 2 ) / 2 } ;
int CheckPR4515 [ PR4515b = = 0 ? 1 : - 1 ] ;
2010-08-19 12:39:37 +08:00
// PR7911
extern enum PR7911T PR7911V ; // expected-warning{{ISO C forbids forward references to 'enum' types}}
void PR7911F ( ) {
switch ( PR7911V ) ; // expected-error {{statement requires expression of integer type}}
}
2010-11-09 03:48:17 +08:00
char test5 [ __has_feature ( enumerator_attributes ) ? 1 : - 1 ] ;
2010-11-30 07:18:09 +08:00
// PR8694
// rdar://8707031
void PR8694 ( int * e ) / / expected - note { { passing argument to parameter ' e ' here } }
{
}
void crash ( enum E * e ) / / expected - warning { { declaration of ' enum E ' will not be visible outside of this function } } \
// expected-warning {{ISO C forbids forward references to 'enum' types}}
{
PR8694 ( e ) ; // expected-warning {{incompatible pointer types passing 'enum E *' to parameter of type 'int *'}}
}
2012-02-07 12:34:38 +08:00
typedef enum { NegativeShort = ( short ) - 1 } NegativeShortEnum ;
int NegativeShortTest [ NegativeShort = = - 1 ? 1 : - 1 ] ;
2015-09-02 11:27:15 +08:00
// PR24610
enum Color { Red , Green , Blue } ; // expected-note{{previous use is here}}
typedef struct Color NewColor ; // expected-error {{use of 'Color' with tag type that does not match previous declaration}}