blob: 395a1a9ef961b0eede23588ce8915cda8105529f [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
Eli Friedman16c209612009-08-23 00:27:47 +000027int function_pointers(int (*a)(int), int (*b)(int), void (*c)(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}}
Eli Friedman16c209612009-08-23 00:27:47 +000030 return a > c; // expected-warning {{comparison of distinct pointer types}}
Chris Lattnerd466ea12009-06-30 06:24:05 +000031 return a == (void *) 0;
Eli Friedman16c209612009-08-23 00:27:47 +000032 return a == (void *) 1; // expected-warning {{equality comparison between function pointer and void pointer}}
Chris Lattnerd466ea12009-06-30 06:24:05 +000033}
Douglas Gregore64c1962009-07-06 20:14:23 +000034
Eli Friedman16c209612009-08-23 00:27:47 +000035int void_pointers(void* foo) {
36 return foo == (void*) 0;
37 return foo == (void*) 1;
Douglas Gregore64c1962009-07-06 20:14:23 +000038}