blob: b7c5c25ddb6f4451ce0acb48f6b5296df293a6a0 [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;
8 return C != 0;
9}
10
Steve Naroff77878cc2007-08-27 04:08:11 +000011int equal(char *a, const char *b)
12{
13 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
21int pointers(int *a)
22{
23 return a > 0; // expected-warning {{ordered comparison between pointer and integer}}
24 return a > (void *)0; // expected-warning {{comparison of distinct pointer types}}
25}
26
27int function_pointers(int (*a)(int), int (*b)(int))
28{
29 return a > b; // expected-warning {{ordered comparison of function pointers}}
30 return function_pointers > function_pointers; // expected-warning {{ordered comparison of function pointers}}
31 return a == (void *) 0;
32 return a == (void *) 1; // expected-warning {{comparison of distinct pointer types}}
33}
Douglas Gregorf9334372009-07-06 20:14:23 +000034
35int void_pointers(void *foo)
36{
37 return foo == NULL;
38}