blob: 6b64bac37da5e42c33315dab74a1f4766b1444c2 [file] [log] [blame]
Daniel Dunbara45cf5b2009-03-24 02:24:46 +00001// RUN: clang-cc -fsyntax-only -pedantic -verify %s
Chris Lattner1895e582007-08-26 01:10:14 +00002
Douglas Gregore64c1962009-07-06 20:14:23 +00003#include <stddef.h>
4
Chris Lattner1895e582007-08-26 01:10:14 +00005int test(char *C) { // nothing here should warn.
6 return C != ((void*)0);
7 return C != (void*)0;
Chris Lattnerd99bd522009-08-23 00:03:44 +00008 return C != 0;
9 return C != 1; // expected-warning {{comparison between pointer and integer ('char *' and 'int')}}
Chris Lattner1895e582007-08-26 01:10:14 +000010}
11
Chris Lattnerf8344db2009-08-22 18:58:31 +000012int equal(char *a, const char *b) {
Steve Naroff808eb8f2007-08-27 04:08:11 +000013 return a == b;
14}
Eli Friedmand49a7202008-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 Lattnerd466ea12009-06-30 06:24:05 +000020
Chris Lattnerf8344db2009-08-22 18:58:31 +000021int pointers(int *a) {
Chris Lattnerd99bd522009-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 Lattnerd466ea12009-06-30 06:24:05 +000024 return a > (void *)0; // expected-warning {{comparison of distinct pointer types}}
25}
26
Chris Lattnerf8344db2009-08-22 18:58:31 +000027int function_pointers(int (*a)(int), int (*b)(int)) {
Chris Lattnerd466ea12009-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 Gregore64c1962009-07-06 20:14:23 +000033
Chris Lattnerf8344db2009-08-22 18:58:31 +000034int void_pointers(void *foo) {
Douglas Gregore64c1962009-07-06 20:14:23 +000035 return foo == NULL;
36}