compare.c revision f93343764765b24f53e389c7dd35f90901925451
1// RUN: clang-cc -fsyntax-only -pedantic -verify %s
2
3#include <stddef.h>
4
5int test(char *C) { // nothing here should warn.
6  return C != ((void*)0);
7  return C != (void*)0;
8  return C != 0;
9}
10
11int equal(char *a, const char *b)
12{
13    return a == b;
14}
15
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}
20
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}
34
35int void_pointers(void *foo)
36{
37  return foo == NULL;
38}
39