Douglas Gregor | 35de813 | 2009-11-06 05:24:12 +0000 | [diff] [blame] | 1 | // RUN: clang-cc -fsyntax-only -verify -pedantic -Wsign-compare %s |
Steve Naroff | b6d54e5 | 2008-01-08 01:11:38 +0000 | [diff] [blame] | 2 | void foo() { |
| 3 | *(0 ? (double *)0 : (void *)0) = 0; |
Steve Naroff | 890d93e | 2008-01-30 21:50:43 +0000 | [diff] [blame] | 4 | // FIXME: GCC doesn't consider the the following two statements to be errors. |
Steve Naroff | aa58f00 | 2008-01-14 16:10:57 +0000 | [diff] [blame] | 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}} |
Steve Naroff | 890d93e | 2008-01-30 21:50:43 +0000 | [diff] [blame] | 7 | *(0 ? (double *)0 : (int *)(void *)0) = 0; // expected-error {{incomplete type 'void' is not assignable}} expected-warning {{pointer type mismatch ('double *' and 'int *')}} |
Steve Naroff | aaffbf7 | 2008-01-14 02:53:34 +0000 | [diff] [blame] | 8 | *(0 ? (double *)0 : (double *)(void *)0) = 0; |
| 9 | *((void *) 0) = 0; // expected-error {{incomplete type 'void' is not assignable}} |
Steve Naroff | b6d54e5 | 2008-01-08 01:11:38 +0000 | [diff] [blame] | 10 | double *dp; |
| 11 | int *ip; |
| 12 | void *vp; |
| 13 | |
| 14 | dp = vp; |
| 15 | vp = dp; |
Steve Naroff | aaffbf7 | 2008-01-14 02:53:34 +0000 | [diff] [blame] | 16 | ip = dp; // expected-warning {{incompatible pointer types assigning 'double *', expected 'int *'}} |
| 17 | dp = ip; // expected-warning {{incompatible pointer types assigning 'int *', expected 'double *'}} |
Steve Naroff | b6d54e5 | 2008-01-08 01:11:38 +0000 | [diff] [blame] | 18 | dp = 0 ? (double *)0 : (void *)0; |
| 19 | vp = 0 ? (double *)0 : (void *)0; |
Steve Naroff | aaffbf7 | 2008-01-14 02:53:34 +0000 | [diff] [blame] | 20 | ip = 0 ? (double *)0 : (void *)0; // expected-warning {{incompatible pointer types assigning 'double *', expected 'int *'}} |
Eli Friedman | f76f5ed | 2008-02-10 23:14:16 +0000 | [diff] [blame] | 21 | |
| 22 | const int *cip; |
| 23 | vp = (0 ? vp : cip); // expected-warning {{discards qualifiers}} |
| 24 | vp = (0 ? cip : vp); // expected-warning {{discards qualifiers}} |
Eli Friedman | 4c721d3 | 2008-02-12 08:23:06 +0000 | [diff] [blame] | 25 | |
| 26 | int i = 2; |
| 27 | int (*pf)[2]; |
| 28 | int (*pv)[i]; |
| 29 | pf = (i ? pf : pv); |
Eli Friedman | bab9696 | 2008-02-12 08:46:17 +0000 | [diff] [blame] | 30 | |
| 31 | enum {xxx,yyy,zzz} e, *ee; |
| 32 | short x; |
| 33 | ee = ee ? &x : ee ? &i : &e; // expected-warning {{pointer type mismatch}} |
Eli Friedman | 4b3f9b3 | 2008-02-13 17:29:58 +0000 | [diff] [blame] | 34 | |
| 35 | typedef void *asdf; |
| 36 | *(0 ? (asdf) 0 : &x) = 10; |
John McCall | b13c87f | 2009-11-05 09:23:39 +0000 | [diff] [blame] | 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 ? (unsigned) EVal : (int) test0; // expected-warning {{operands of ? are integers of different signs}} |
Steve Naroff | b6d54e5 | 2008-01-08 01:11:38 +0000 | [diff] [blame] | 56 | } |
| 57 | |
Steve Naroff | e701c0a | 2008-05-12 21:44:38 +0000 | [diff] [blame] | 58 | int Postgresql() { |
| 59 | char x; |
| 60 | 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}} |
| 61 | } |
Steve Naroff | 9158804 | 2009-04-08 17:05:15 +0000 | [diff] [blame] | 62 | |
| 63 | #define nil ((void*) 0) |
| 64 | |
| 65 | extern int f1(void); |
| 66 | |
| 67 | int f0(int a) { |
| 68 | // GCC considers this a warning. |
| 69 | 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 *', expected 'int'}} |
| 70 | } |