blob: 395a1a9ef961b0eede23588ce8915cda8105529f [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
Douglas Gregorf9334372009-07-06 20:14:23 +00003#include <stddef.h>
4
Chris Lattnerd28f8152007-08-26 01:10:14 +00005int test(char *C) { // nothing here should warn.
6 return C != ((void*)0);
7 return C != (void*)0;
Chris Lattner06c0f5b2009-08-23 00:03:44 +00008 return C != 0;
9 return C != 1; // expected-warning {{comparison between pointer and integer ('char *' and 'int')}}
Chris Lattnerd28f8152007-08-26 01:10:14 +000010}
11
Chris Lattner6365e3e2009-08-22 18:58:31 +000012int equal(char *a, const char *b) {
Steve Naroff77878cc2007-08-27 04:08:11 +000013 return a == b;
14}
Eli Friedman4e92acf2008-02-06 04:53:22 +000015
16int arrays(char (*a)[5], char(*b)[10], char(*c)[5]) {
17 int d = (a == c);
18 return a == b; // expected-warning {{comparison of distinct pointer types}}
19}
Chris Lattner149f1382009-06-30 06:24:05 +000020
Chris Lattner6365e3e2009-08-22 18:58:31 +000021int pointers(int *a) {
Chris Lattner06c0f5b2009-08-23 00:03:44 +000022 return a > 0; // expected-warning {{ordered comparison between pointer and zero ('int *' and 'int') is an extension}}
23 return a > 42; // expected-warning {{ordered comparison between pointer and integer ('int *' and 'int')}}
Chris Lattner149f1382009-06-30 06:24:05 +000024 return a > (void *)0; // expected-warning {{comparison of distinct pointer types}}
25}
26
Eli Friedman3075e762009-08-23 00:27:47 +000027int function_pointers(int (*a)(int), int (*b)(int), void (*c)(int)) {
Chris Lattner149f1382009-06-30 06:24:05 +000028 return a > b; // expected-warning {{ordered comparison of function pointers}}
29 return function_pointers > function_pointers; // expected-warning {{ordered comparison of function pointers}}
Eli Friedman3075e762009-08-23 00:27:47 +000030 return a > c; // expected-warning {{comparison of distinct pointer types}}
Chris Lattner149f1382009-06-30 06:24:05 +000031 return a == (void *) 0;
Eli Friedman3075e762009-08-23 00:27:47 +000032 return a == (void *) 1; // expected-warning {{equality comparison between function pointer and void pointer}}
Chris Lattner149f1382009-06-30 06:24:05 +000033}
Douglas Gregorf9334372009-07-06 20:14:23 +000034
Eli Friedman3075e762009-08-23 00:27:47 +000035int void_pointers(void* foo) {
36 return foo == (void*) 0;
37 return foo == (void*) 1;
Douglas Gregorf9334372009-07-06 20:14:23 +000038}