2011-07-21 10:46:28 +08:00
// RUN: %clang_cc1 -fsyntax-only -verify -pedantic -Wsign-conversion %s
2008-01-08 09:11:38 +08:00
void foo ( ) {
* ( 0 ? ( double * ) 0 : ( void * ) 0 ) = 0 ;
2008-01-31 05:50:43 +08:00
// FIXME: GCC doesn't consider the the following two statements to be errors.
2008-01-15 00:10:57 +08:00
* ( 0 ? ( double * ) 0 : ( void * ) ( int * ) 0 ) = 0 ; // expected-error {{incomplete type 'void' is not assignable}}
* ( 0 ? ( double * ) 0 : ( void * ) ( double * ) 0 ) = 0 ; // expected-error {{incomplete type 'void' is not assignable}}
2008-01-31 05:50:43 +08:00
* ( 0 ? ( double * ) 0 : ( int * ) ( void * ) 0 ) = 0 ; // expected-error {{incomplete type 'void' is not assignable}} expected-warning {{pointer type mismatch ('double *' and 'int *')}}
2008-01-14 10:53:34 +08:00
* ( 0 ? ( double * ) 0 : ( double * ) ( void * ) 0 ) = 0 ;
* ( ( void * ) 0 ) = 0 ; // expected-error {{incomplete type 'void' is not assignable}}
2008-01-08 09:11:38 +08:00
double * dp ;
int * ip ;
void * vp ;
dp = vp ;
vp = dp ;
2010-04-09 08:35:39 +08:00
ip = dp ; // expected-warning {{incompatible pointer types assigning to 'int *' from 'double *'}}
dp = ip ; // expected-warning {{incompatible pointer types assigning to 'double *' from 'int *'}}
2008-01-08 09:11:38 +08:00
dp = 0 ? ( double * ) 0 : ( void * ) 0 ;
vp = 0 ? ( double * ) 0 : ( void * ) 0 ;
2010-04-09 08:35:39 +08:00
ip = 0 ? ( double * ) 0 : ( void * ) 0 ; // expected-warning {{incompatible pointer types assigning to 'int *' from 'double *'}}
2008-02-11 07:14:16 +08:00
const int * cip ;
vp = ( 0 ? vp : cip ) ; // expected-warning {{discards qualifiers}}
vp = ( 0 ? cip : vp ) ; // expected-warning {{discards qualifiers}}
2008-02-12 16:23:06 +08:00
int i = 2 ;
int ( * pf ) [ 2 ] ;
int ( * pv ) [ i ] ;
pf = ( i ? pf : pv ) ;
2008-02-12 16:46:17 +08:00
enum { xxx , yyy , zzz } e , * ee ;
short x ;
ee = ee ? & x : ee ? & i : & e ; // expected-warning {{pointer type mismatch}}
2008-02-14 01:29:58 +08:00
typedef void * asdf ;
* ( 0 ? ( asdf ) 0 : & x ) = 10 ;
2009-11-05 17:23:39 +08:00
unsigned long test0 = 5 ;
2011-07-21 10:46:28 +08:00
test0 = test0 ? ( long ) test0 : test0 ; // expected-warning {{operand of ? changes signedness: 'long' to 'unsigned long'}}
test0 = test0 ? ( int ) test0 : test0 ; // expected-warning {{operand of ? changes signedness: 'int' to 'unsigned long'}}
test0 = test0 ? ( short ) test0 : test0 ; // expected-warning {{operand of ? changes signedness: 'short' to 'unsigned long'}}
test0 = test0 ? test0 : ( long ) test0 ; // expected-warning {{operand of ? changes signedness: 'long' to 'unsigned long'}}
test0 = test0 ? test0 : ( int ) test0 ; // expected-warning {{operand of ? changes signedness: 'int' to 'unsigned long'}}
test0 = test0 ? test0 : ( short ) test0 ; // expected-warning {{operand of ? changes signedness: 'short' to 'unsigned long'}}
2009-11-05 17:23:39 +08:00
test0 = test0 ? test0 : ( long ) 10 ;
test0 = test0 ? test0 : ( int ) 10 ;
test0 = test0 ? test0 : ( short ) 10 ;
test0 = test0 ? ( long ) 10 : test0 ;
test0 = test0 ? ( int ) 10 : test0 ;
test0 = test0 ? ( short ) 10 : test0 ;
2011-07-21 10:46:28 +08:00
int test1 ;
2009-11-05 17:23:39 +08:00
enum Enum { EVal } ;
test0 = test0 ? EVal : test0 ;
2011-07-21 10:46:28 +08:00
test1 = test0 ? EVal : ( int ) test0 ;
test0 = test0 ?
2010-05-06 16:58:33 +08:00
( unsigned ) EVal
2011-07-21 10:46:28 +08:00
: ( int ) test0 ; // expected-warning {{operand of ? changes signedness: 'int' to 'unsigned long'}}
test0 = test0 ? EVal : test1 ; // expected-warning {{operand of ? changes signedness: 'int' to 'unsigned long'}}
test0 = test0 ? test1 : EVal ; // expected-warning {{operand of ? changes signedness: 'int' to 'unsigned long'}}
2008-01-08 09:11:38 +08:00
}
2008-05-13 05:44:38 +08:00
int Postgresql ( ) {
char x ;
return ( ( ( ( & x ) ! = ( ( void * ) 0 ) ) ? ( * ( & x ) = ( ( char ) 1 ) ) : ( void ) ( ( void * ) 0 ) ) , ( unsigned long ) ( ( void * ) 0 ) ) ; // expected-warning {{C99 forbids conditional expressions with only one void side}}
}
2009-04-09 01:05:15 +08:00
# define nil ((void*) 0)
extern int f1 ( void ) ;
int f0 ( int a ) {
// GCC considers this a warning.
2010-04-09 08:35:39 +08:00
return a ? f1 ( ) : nil ; // expected-warning {{pointer/integer type mismatch in conditional expression ('int' and 'void *')}} expected-warning {{incompatible pointer to integer conversion returning 'void *' from a function with result type 'int'}}
2009-04-09 01:05:15 +08:00
}
2010-05-06 16:58:33 +08:00
int f2 ( int x ) {
// We can suppress this because the immediate context wants an int.
return ( x ! = 0 ) ? 0U : x ;
}
2011-02-19 07:54:50 +08:00
# define NULL (void*)0
void PR9236 ( ) {
struct A { int i ; } A1 ;
( void ) ( 1 ? A1 : NULL ) ; // expected-error{{non-pointer operand type 'struct A' incompatible with NULL}}
( void ) ( 1 ? NULL : A1 ) ; // expected-error{{non-pointer operand type 'struct A' incompatible with NULL}}
( void ) ( 1 ? 0 : A1 ) ; // expected-error{{incompatible operand types}}
( void ) ( 1 ? ( void * ) 0 : A1 ) ; // expected-error{{incompatible operand types}}
( void ) ( 1 ? A1 : ( void * ) 0 ) ; // expected-error{{incompatible operand types}}
( void ) ( 1 ? A1 : ( NULL ) ) ; // expected-error{{non-pointer operand type 'struct A' incompatible with NULL}}
}