freebsd-dev/test/Sema/compare.c

37 lines
1.4 KiB
C
Raw Normal View History

2009-06-02 17:58:47 +00:00
// RUN: clang-cc -fsyntax-only -pedantic -verify %s
int test(char *C) { // nothing here should warn.
return C != ((void*)0);
return C != (void*)0;
2009-10-14 18:03:49 +00:00
return C != 0;
return C != 1; // expected-warning {{comparison between pointer and integer ('char *' and 'int')}}
2009-06-02 17:58:47 +00:00
}
2009-10-14 18:03:49 +00:00
int equal(char *a, const char *b) {
2009-06-02 17:58:47 +00:00
return a == b;
}
int arrays(char (*a)[5], char(*b)[10], char(*c)[5]) {
int d = (a == c);
return a == b; // expected-warning {{comparison of distinct pointer types}}
}
2009-07-04 13:58:54 +00:00
2009-10-14 18:03:49 +00:00
int pointers(int *a) {
return a > 0; // expected-warning {{ordered comparison between pointer and zero ('int *' and 'int') is an extension}}
return a > 42; // expected-warning {{ordered comparison between pointer and integer ('int *' and 'int')}}
2009-07-04 13:58:54 +00:00
return a > (void *)0; // expected-warning {{comparison of distinct pointer types}}
}
2009-10-14 18:03:49 +00:00
int function_pointers(int (*a)(int), int (*b)(int), void (*c)(int)) {
2009-07-04 13:58:54 +00:00
return a > b; // expected-warning {{ordered comparison of function pointers}}
return function_pointers > function_pointers; // expected-warning {{ordered comparison of function pointers}}
2009-10-14 18:03:49 +00:00
return a > c; // expected-warning {{comparison of distinct pointer types}}
2009-07-04 13:58:54 +00:00
return a == (void *) 0;
2009-10-14 18:03:49 +00:00
return a == (void *) 1; // expected-warning {{equality comparison between function pointer and void pointer}}
}
int void_pointers(void* foo) {
return foo == (void*) 0;
return foo == (void*) 1;
2009-07-04 13:58:54 +00:00
}