blob: 2afaab523be93b5a07f18d74a53ee173aeea0b48 [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
Chris Lattner6365e3e2009-08-22 18:58:31 +000011int equal(char *a, const char *b) {
Steve Naroff77878cc2007-08-27 04:08:11 +000012 return a == b;
13}
Eli Friedman4e92acf2008-02-06 04:53:22 +000014
15int arrays(char (*a)[5], char(*b)[10], char(*c)[5]) {
16 int d = (a == c);
17 return a == b; // expected-warning {{comparison of distinct pointer types}}
18}
Chris Lattner149f1382009-06-30 06:24:05 +000019
Chris Lattner6365e3e2009-08-22 18:58:31 +000020int pointers(int *a) {
21 return a > 0; // no warning. rdar://7163039
Chris Lattner149f1382009-06-30 06:24:05 +000022 return a > (void *)0; // expected-warning {{comparison of distinct pointer types}}
23}
24
Chris Lattner6365e3e2009-08-22 18:58:31 +000025int function_pointers(int (*a)(int), int (*b)(int)) {
Chris Lattner149f1382009-06-30 06:24:05 +000026 return a > b; // expected-warning {{ordered comparison of function pointers}}
27 return function_pointers > function_pointers; // expected-warning {{ordered comparison of function pointers}}
28 return a == (void *) 0;
29 return a == (void *) 1; // expected-warning {{comparison of distinct pointer types}}
30}
Douglas Gregorf9334372009-07-06 20:14:23 +000031
Chris Lattner6365e3e2009-08-22 18:58:31 +000032int void_pointers(void *foo) {
Douglas Gregorf9334372009-07-06 20:14:23 +000033 return foo == NULL;
34}