2009-11-06 13:24:12 +08:00
|
|
|
// RUN: clang-cc -fsyntax-only -pedantic -verify -Wsign-compare %s
|
2007-08-26 09:10:14 +08:00
|
|
|
|
|
|
|
int test(char *C) { // nothing here should warn.
|
|
|
|
return C != ((void*)0);
|
|
|
|
return C != (void*)0;
|
2009-08-23 08:03:44 +08:00
|
|
|
return C != 0;
|
|
|
|
return C != 1; // expected-warning {{comparison between pointer and integer ('char *' and 'int')}}
|
2007-08-26 09:10:14 +08:00
|
|
|
}
|
|
|
|
|
2009-11-05 08:40:04 +08:00
|
|
|
int ints(long a, unsigned long b) {
|
|
|
|
return (a == b) + // expected-warning {{comparison of integers of different signs}}
|
|
|
|
((int)a == b) + // expected-warning {{comparison of integers of different signs}}
|
|
|
|
((short)a == b) + // expected-warning {{comparison of integers of different signs}}
|
|
|
|
(a == (unsigned int) b) + // expected-warning {{comparison of integers of different signs}}
|
|
|
|
(a == (unsigned short) b); // expected-warning {{comparison of integers of different signs}}
|
2009-11-05 17:23:39 +08:00
|
|
|
|
|
|
|
enum Enum {B};
|
|
|
|
return (a == B) +
|
|
|
|
((int)a == B) +
|
|
|
|
((short)a == B) +
|
|
|
|
(a == (unsigned int) B) + // expected-warning {{comparison of integers of different signs}}
|
|
|
|
(a == (unsigned short) B); // expected-warning {{comparison of integers of different signs}}
|
|
|
|
|
|
|
|
// Should be able to prove all of these are non-negative.
|
|
|
|
return (b == (long) B) +
|
|
|
|
(b == (int) B) +
|
|
|
|
(b == (short) B);
|
2009-11-05 08:40:04 +08:00
|
|
|
}
|
|
|
|
|
2009-08-23 02:58:31 +08:00
|
|
|
int equal(char *a, const char *b) {
|
2007-08-27 12:08:11 +08:00
|
|
|
return a == b;
|
|
|
|
}
|
2008-02-06 12:53:22 +08:00
|
|
|
|
|
|
|
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-06-30 14:24:05 +08:00
|
|
|
|
2009-08-23 02:58:31 +08:00
|
|
|
int pointers(int *a) {
|
2009-08-23 08:03:44 +08:00
|
|
|
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-06-30 14:24:05 +08:00
|
|
|
return a > (void *)0; // expected-warning {{comparison of distinct pointer types}}
|
|
|
|
}
|
|
|
|
|
2009-08-23 08:27:47 +08:00
|
|
|
int function_pointers(int (*a)(int), int (*b)(int), void (*c)(int)) {
|
2009-06-30 14:24:05 +08:00
|
|
|
return a > b; // expected-warning {{ordered comparison of function pointers}}
|
|
|
|
return function_pointers > function_pointers; // expected-warning {{ordered comparison of function pointers}}
|
2009-08-23 08:27:47 +08:00
|
|
|
return a > c; // expected-warning {{comparison of distinct pointer types}}
|
2009-06-30 14:24:05 +08:00
|
|
|
return a == (void *) 0;
|
2009-08-23 08:27:47 +08:00
|
|
|
return a == (void *) 1; // expected-warning {{equality comparison between function pointer and void pointer}}
|
2009-06-30 14:24:05 +08:00
|
|
|
}
|
2009-07-07 04:14:23 +08:00
|
|
|
|
2009-08-23 08:27:47 +08:00
|
|
|
int void_pointers(void* foo) {
|
|
|
|
return foo == (void*) 0;
|
|
|
|
return foo == (void*) 1;
|
2009-07-07 04:14:23 +08:00
|
|
|
}
|