2011-06-14 14:38:10 +08:00
// RUN: %clang %s -ffreestanding -fsyntax-only -Xclang -verify -pedantic -fpascal-strings -std=c99
2008-12-12 15:01:24 +08:00
2009-02-27 12:46:32 +08:00
# include <stdint.h>
# include <limits.h>
2009-04-26 06:37:12 +08:00
int a ( ) { int p ; * ( 1 ? & p : ( void * ) ( 0 & & ( a ( ) , 1 ) ) ) = 10 ; } // expected-error {{incomplete type 'void' is not assignable}}
2008-12-12 15:01:24 +08:00
// rdar://6091492 - ?: with __builtin_constant_p as the operand is an i-c-e.
int expr ;
char w [ __builtin_constant_p ( expr ) ? expr : 1 ] ;
2010-10-09 12:51:06 +08:00
char v [ sizeof ( __builtin_constant_p ( 0 ) ) = = sizeof ( int ) ? 1 : - 1 ] ;
2008-12-12 15:01:24 +08:00
2011-10-25 02:26:35 +08:00
int implicitConversion = 1.0 ;
char floatArith [ ( int ) ( 1.0 + 2.0 ) ] ; // expected-warning {{must be an integer constant expression}}
2008-12-13 02:00:51 +08:00
// __builtin_constant_p as the condition of ?: allows arbitrary foldable
// constants to be transmogrified into i-c-e's.
char b [ __builtin_constant_p ( ( int ) ( 1.0 + 2.0 ) ) ? ( int ) ( 1.0 + 2.0 ) : - 1 ] ;
struct c {
int a : ( // expected-error {{expression is not an integer constant expression}}
__builtin_constant_p ( ( int ) ( 1.0 + 2.0 ) ) ? ( int ) ( 1.0 +
expr // expected-note {{subexpression not valid in an integer constant expression}}
) : - 1 ) ;
} ;
2008-12-12 15:01:24 +08:00
void test1 ( int n , int * p ) { * ( n ? p : ( void * ) ( 7 - 7 ) ) = 1 ; }
void test2 ( int n , int * p ) { * ( n ? p : ( void * ) 0 ) = 1 ; }
char array [ 1024 / ( sizeof ( long ) ) ] ;
int x [ ' \xBb ' = = ( char ) 187 ? 1 : - 1 ] ;
// PR1992
void func ( int x )
{
switch ( x ) {
case sizeof ( " abc " ) : break ;
case sizeof ( " loooong " ) : func ( 4 ) ;
case sizeof ( " \ ploooong " ) : func ( 4 ) ;
}
}
// rdar://4213768
int expr ;
char y [ __builtin_constant_p ( expr ) ? - 1 : 1 ] ;
char z [ __builtin_constant_p ( 4 ) ? 1 : - 1 ] ;
2009-02-27 12:46:32 +08:00
// Comma tests
2010-09-20 07:03:35 +08:00
int comma1 [ 0 ? 1 , 2 : 3 ] ; // expected-warning {{expression result unused}}
int comma2 [ 1 | | ( 1 , 2 ) ] ; / / expected - warning { { expression result unused } } \
2011-08-16 01:50:06 +08:00
/ / expected - warning { { use of logical ' | | ' with constant operand } } \
// expected-note {{use '|' for a bitwise operation}}
2010-09-20 07:03:35 +08:00
int comma3 [ ( 1 , 2 ) ] ; / / expected - warning { { size of static array must be an integer constant expression } } \
// expected-warning {{expression result unused}}
2009-02-27 12:46:32 +08:00
// Pointer + __builtin_constant_p
char pbcp [ __builtin_constant_p ( 4 ) ? ( intptr_t ) & expr : 0 ] ; // expected-error {{variable length array declaration not allowed at file scope}}
2011-02-23 09:52:04 +08:00
int illegaldiv1a [ 1 | | 1 / 0 ] ; // expected-warning {{division by zero is undefined}}
int illegaldiv1b [ 1 & & 1 / 0 ] ; // expected-warning {{division by zero is undefined}} expected-error{{variable length array declaration not allowed at file scope}}
2010-01-13 05:23:57 +08:00
int illegaldiv2 [ 1 / 0 ] ; / / expected - error { { variable length array declaration not allowed at file scope } } \
// expected-warning {{division by zero is undefined}}
2009-02-27 12:46:32 +08:00
int illegaldiv3 [ INT_MIN / - 1 ] ; // expected-error {{variable length array declaration not allowed at file scope}}
2011-02-26 16:27:17 +08:00
// PR9262
int illegaldiv4 [ 0 / ( 1 / 0 ) ] ; // expected-warning {{division by zero is undefined}} expected-error {{variable length array declaration not allowed at file scope}}
2009-02-27 12:46:32 +08:00
2009-04-28 11:13:54 +08:00
int chooseexpr [ __builtin_choose_expr ( 1 , 1 , expr ) ] ;
int realop [ ( __real__ 4 ) = = 4 ? 1 : - 1 ] ;
int imagop [ ( __imag__ 4 ) = = 0 ? 1 : - 1 ] ;