blob: 6b64bac37da5e42c33315dab74a1f4766b1444c2 [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
Chris Lattner6365e3e2009-08-22 18:58:31 +000027int function_pointers(int (*a)(int), int (*b)(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}}
30 return a == (void *) 0;
31 return a == (void *) 1; // expected-warning {{comparison of distinct pointer types}}
32}
Douglas Gregorf9334372009-07-06 20:14:23 +000033
Chris Lattner6365e3e2009-08-22 18:58:31 +000034int void_pointers(void *foo) {
Douglas Gregorf9334372009-07-06 20:14:23 +000035 return foo == NULL;
36}