compare.c revision 6365e3e22bcec4b95c5b1ed47d501134b375a75a
1// RUN: clang-cc -fsyntax-only -pedantic -verify %s 2 3#include <stddef.h> 4 5int test(char *C) { // nothing here should warn. 6 return C != ((void*)0); 7 return C != (void*)0; 8 return C != 0; 9} 10 11int equal(char *a, const char *b) { 12 return a == b; 13} 14 15int 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} 19 20int pointers(int *a) { 21 return a > 0; // no warning. rdar://7163039 22 return a > (void *)0; // expected-warning {{comparison of distinct pointer types}} 23} 24 25int function_pointers(int (*a)(int), int (*b)(int)) { 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} 31 32int void_pointers(void *foo) { 33 return foo == NULL; 34} 35