Daniel Dunbar | d7d5f02 | 2009-03-24 02:24:46 +0000 | [diff] [blame] | 1 | // RUN: clang-cc -fsyntax-only -pedantic -verify %s |
Chris Lattner | d28f815 | 2007-08-26 01:10:14 +0000 | [diff] [blame] | 2 | |
Douglas Gregor | f933437 | 2009-07-06 20:14:23 +0000 | [diff] [blame] | 3 | #include <stddef.h> |
| 4 | |
Chris Lattner | d28f815 | 2007-08-26 01:10:14 +0000 | [diff] [blame] | 5 | int test(char *C) { // nothing here should warn. |
| 6 | return C != ((void*)0); |
| 7 | return C != (void*)0; |
| 8 | return C != 0; |
| 9 | } |
| 10 | |
Chris Lattner | 6365e3e | 2009-08-22 18:58:31 +0000 | [diff] [blame^] | 11 | int equal(char *a, const char *b) { |
Steve Naroff | 77878cc | 2007-08-27 04:08:11 +0000 | [diff] [blame] | 12 | return a == b; |
| 13 | } |
Eli Friedman | 4e92acf | 2008-02-06 04:53:22 +0000 | [diff] [blame] | 14 | |
| 15 | int arrays(char (*a)[5], char(*b)[10], char(*c)[5]) { |
| 16 | int d = (a == c); |
| 17 | return a == b; // expected-warning {{comparison of distinct pointer types}} |
| 18 | } |
Chris Lattner | 149f138 | 2009-06-30 06:24:05 +0000 | [diff] [blame] | 19 | |
Chris Lattner | 6365e3e | 2009-08-22 18:58:31 +0000 | [diff] [blame^] | 20 | int pointers(int *a) { |
| 21 | return a > 0; // no warning. rdar://7163039 |
Chris Lattner | 149f138 | 2009-06-30 06:24:05 +0000 | [diff] [blame] | 22 | return a > (void *)0; // expected-warning {{comparison of distinct pointer types}} |
| 23 | } |
| 24 | |
Chris Lattner | 6365e3e | 2009-08-22 18:58:31 +0000 | [diff] [blame^] | 25 | int function_pointers(int (*a)(int), int (*b)(int)) { |
Chris Lattner | 149f138 | 2009-06-30 06:24:05 +0000 | [diff] [blame] | 26 | return a > b; // expected-warning {{ordered comparison of function pointers}} |
| 27 | return function_pointers > function_pointers; // expected-warning {{ordered comparison of function pointers}} |
| 28 | return a == (void *) 0; |
| 29 | return a == (void *) 1; // expected-warning {{comparison of distinct pointer types}} |
| 30 | } |
Douglas Gregor | f933437 | 2009-07-06 20:14:23 +0000 | [diff] [blame] | 31 | |
Chris Lattner | 6365e3e | 2009-08-22 18:58:31 +0000 | [diff] [blame^] | 32 | int void_pointers(void *foo) { |
Douglas Gregor | f933437 | 2009-07-06 20:14:23 +0000 | [diff] [blame] | 33 | return foo == NULL; |
| 34 | } |