blob: 50b40e459c39e783dbf7cffb684b1e5fb994a197 [file] [log] [blame]
Daniel Dunbard7d5f022009-03-24 02:24:46 +00001// RUN: clang-cc -fsyntax-only -pedantic -verify %s
Chris Lattnerd28f8152007-08-26 01:10:14 +00002
3int test(char *C) { // nothing here should warn.
4 return C != ((void*)0);
5 return C != (void*)0;
Chris Lattner06c0f5b2009-08-23 00:03:44 +00006 return C != 0;
7 return C != 1; // expected-warning {{comparison between pointer and integer ('char *' and 'int')}}
Chris Lattnerd28f8152007-08-26 01:10:14 +00008}
9
John McCall45aa4552009-11-05 00:40:04 +000010int ints(long a, unsigned long b) {
11 return (a == b) + // expected-warning {{comparison of integers of different signs}}
12 ((int)a == b) + // expected-warning {{comparison of integers of different signs}}
13 ((short)a == b) + // expected-warning {{comparison of integers of different signs}}
14 (a == (unsigned int) b) + // expected-warning {{comparison of integers of different signs}}
15 (a == (unsigned short) b); // expected-warning {{comparison of integers of different signs}}
16}
17
Chris Lattner6365e3e2009-08-22 18:58:31 +000018int equal(char *a, const char *b) {
Steve Naroff77878cc2007-08-27 04:08:11 +000019 return a == b;
20}
Eli Friedman4e92acf2008-02-06 04:53:22 +000021
22int arrays(char (*a)[5], char(*b)[10], char(*c)[5]) {
23 int d = (a == c);
24 return a == b; // expected-warning {{comparison of distinct pointer types}}
25}
Chris Lattner149f1382009-06-30 06:24:05 +000026
Chris Lattner6365e3e2009-08-22 18:58:31 +000027int pointers(int *a) {
Chris Lattner06c0f5b2009-08-23 00:03:44 +000028 return a > 0; // expected-warning {{ordered comparison between pointer and zero ('int *' and 'int') is an extension}}
29 return a > 42; // expected-warning {{ordered comparison between pointer and integer ('int *' and 'int')}}
Chris Lattner149f1382009-06-30 06:24:05 +000030 return a > (void *)0; // expected-warning {{comparison of distinct pointer types}}
31}
32
Eli Friedman3075e762009-08-23 00:27:47 +000033int function_pointers(int (*a)(int), int (*b)(int), void (*c)(int)) {
Chris Lattner149f1382009-06-30 06:24:05 +000034 return a > b; // expected-warning {{ordered comparison of function pointers}}
35 return function_pointers > function_pointers; // expected-warning {{ordered comparison of function pointers}}
Eli Friedman3075e762009-08-23 00:27:47 +000036 return a > c; // expected-warning {{comparison of distinct pointer types}}
Chris Lattner149f1382009-06-30 06:24:05 +000037 return a == (void *) 0;
Eli Friedman3075e762009-08-23 00:27:47 +000038 return a == (void *) 1; // expected-warning {{equality comparison between function pointer and void pointer}}
Chris Lattner149f1382009-06-30 06:24:05 +000039}
Douglas Gregorf9334372009-07-06 20:14:23 +000040
Eli Friedman3075e762009-08-23 00:27:47 +000041int void_pointers(void* foo) {
42 return foo == (void*) 0;
43 return foo == (void*) 1;
Douglas Gregorf9334372009-07-06 20:14:23 +000044}