1 // RUN: %clang_cc1 -fsyntax-only -verify -pedantic -Wsign-compare %s 2 void foo() { 3 *(0 ? (double *)0 : (void *)0) = 0; 4 // FIXME: GCC doesn't consider the the following two statements to be errors. 5 *(0 ? (double *)0 : (void *)(int *)0) = 0; // expected-error {{incomplete type 'void' is not assignable}} 6 *(0 ? (double *)0 : (void *)(double *)0) = 0; // expected-error {{incomplete type 'void' is not assignable}} 7 *(0 ? (double *)0 : (int *)(void *)0) = 0; // expected-error {{incomplete type 'void' is not assignable}} expected-warning {{pointer type mismatch ('double *' and 'int *')}} 8 *(0 ? (double *)0 : (double *)(void *)0) = 0; 9 *((void *) 0) = 0; // expected-error {{incomplete type 'void' is not assignable}} 10 double *dp; 11 int *ip; 12 void *vp; 13 14 dp = vp; 15 vp = dp; 16 ip = dp; // expected-warning {{incompatible pointer types assigning to 'int *' from 'double *'}} 17 dp = ip; // expected-warning {{incompatible pointer types assigning to 'double *' from 'int *'}} 18 dp = 0 ? (double *)0 : (void *)0; 19 vp = 0 ? (double *)0 : (void *)0; 20 ip = 0 ? (double *)0 : (void *)0; // expected-warning {{incompatible pointer types assigning to 'int *' from 'double *'}} 21 22 const int *cip; 23 vp = (0 ? vp : cip); // expected-warning {{discards qualifiers}} 24 vp = (0 ? cip : vp); // expected-warning {{discards qualifiers}} 25 26 int i = 2; 27 int (*pf)[2]; 28 int (*pv)[i]; 29 pf = (i ? pf : pv); 30 31 enum {xxx,yyy,zzz} e, *ee; 32 short x; 33 ee = ee ? &x : ee ? &i : &e; // expected-warning {{pointer type mismatch}} 34 35 typedef void *asdf; 36 *(0 ? (asdf) 0 : &x) = 10; 37 38 unsigned long test0 = 5; 39 test0 = test0 ? (long) test0 : test0; // expected-warning {{operands of ? are integers of different signs}} 40 test0 = test0 ? (int) test0 : test0; // expected-warning {{operands of ? are integers of different signs}} 41 test0 = test0 ? (short) test0 : test0; // expected-warning {{operands of ? are integers of different signs}} 42 test0 = test0 ? test0 : (long) test0; // expected-warning {{operands of ? are integers of different signs}} 43 test0 = test0 ? test0 : (int) test0; // expected-warning {{operands of ? are integers of different signs}} 44 test0 = test0 ? test0 : (short) test0; // expected-warning {{operands of ? are integers of different signs}} 45 test0 = test0 ? test0 : (long) 10; 46 test0 = test0 ? test0 : (int) 10; 47 test0 = test0 ? test0 : (short) 10; 48 test0 = test0 ? (long) 10 : test0; 49 test0 = test0 ? (int) 10 : test0; 50 test0 = test0 ? (short) 10 : test0; 51 52 enum Enum { EVal }; 53 test0 = test0 ? EVal : test0; 54 test0 = test0 ? EVal : (int) test0; // okay: EVal is an int 55 test0 = test0 ? // expected-warning {{operands of ? are integers of different signs}} 56 (unsigned) EVal 57 : (int) test0; 58 } 59 60 int Postgresql() { 61 char x; 62 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}} 63 } 64 65 #define nil ((void*) 0) 66 67 extern int f1(void); 68 69 int f0(int a) { 70 // GCC considers this a warning. 71 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'}} 72 } 73 74 int f2(int x) { 75 // We can suppress this because the immediate context wants an int. 76 return (x != 0) ? 0U : x; 77 } 78 79 #define NULL (void*)0 80 81 void PR9236() { 82 struct A {int i;} A1; 83 (void)(1 ? A1 : NULL); // expected-error{{non-pointer operand type 'struct A' incompatible with NULL}} 84 (void)(1 ? NULL : A1); // expected-error{{non-pointer operand type 'struct A' incompatible with NULL}} 85 (void)(1 ? 0 : A1); // expected-error{{incompatible operand types}} 86 (void)(1 ? (void*)0 : A1); // expected-error{{incompatible operand types}} 87 (void)(1 ? A1: (void*)0); // expected-error{{incompatible operand types}} 88 (void)(1 ? A1 : (NULL)); // expected-error{{non-pointer operand type 'struct A' incompatible with NULL}} 89 } 90 91