Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
Douglas Gregor | 0c6db94 | 2009-05-04 06:07:12 +0000 | [diff] [blame] | 2 | |
| 3 | class Base { }; |
| 4 | class Derived1 : public Base { }; |
| 5 | class Derived2 : public Base { }; |
| 6 | |
| 7 | void f0(volatile Base *b, Derived1 *d1, const Derived2 *d2) { |
| 8 | if (b > d1) |
| 9 | return; |
| 10 | if (d1 <= b) |
| 11 | return; |
| 12 | if (b > d2) |
| 13 | return; |
| 14 | if (d1 >= d2) // expected-error{{comparison of distinct}} |
| 15 | return; |
| 16 | } |
| 17 | |
| 18 | void f1(volatile Base *b, Derived1 *d1, const Derived2 *d2) { |
| 19 | if (b == d1) |
| 20 | return; |
| 21 | if (d1 == b) |
| 22 | return; |
| 23 | if (b != d2) |
| 24 | return; |
| 25 | if (d1 == d2) // expected-error{{comparison of distinct}} |
| 26 | return; |
| 27 | } |
Douglas Gregor | 20b3e99 | 2009-08-24 17:42:35 +0000 | [diff] [blame] | 28 | |
| 29 | // PR4691 |
| 30 | int ptrcmp1(void *a, int *b) { |
| 31 | return a < b; |
| 32 | } |
| 33 | int ptrcmp2(long *a, int *b) { |
| 34 | return a < b; // expected-error{{distinct}} |
Daniel Dunbar | 4fcfde4 | 2009-11-08 01:45:36 +0000 | [diff] [blame] | 35 | } |
Sebastian Redl | a439e6f | 2009-11-16 21:03:45 +0000 | [diff] [blame] | 36 | |
| 37 | // PR5509 - Multi-level pointers |
| 38 | int f2() { |
| 39 | typedef int *IntPtr; |
| 40 | typedef IntPtr *IntPtrPtr; |
| 41 | typedef IntPtr const *IntPtrConstPtr; |
| 42 | IntPtrConstPtr i = 0; |
| 43 | IntPtrPtr j = 0; |
| 44 | return i != j; |
| 45 | } |
Douglas Gregor | b4a8999 | 2010-01-11 21:58:49 +0000 | [diff] [blame] | 46 | |
| 47 | // PR5763 |
| 48 | typedef double Matrix4[4][4]; |
| 49 | |
| 50 | bool f(Matrix4 m1, const Matrix4 m2) { |
| 51 | return m1 != m2; |
| 52 | } |
Douglas Gregor | b2cb1cb | 2010-02-25 22:29:57 +0000 | [diff] [blame] | 53 | |
| 54 | // PR6346 |
| 55 | bool f1(bool b, void **p, const void **q) { |
Chris Lattner | 58f9e13 | 2010-09-05 00:04:01 +0000 | [diff] [blame] | 56 | if (p == q) // expected-warning{{comparison of distinct pointer types ('void **' and 'const void **') uses non-standard composite pointer type 'const void *const *'}} |
Douglas Gregor | b2cb1cb | 2010-02-25 22:29:57 +0000 | [diff] [blame] | 57 | return false; |
| 58 | |
Chris Lattner | 58f9e13 | 2010-09-05 00:04:01 +0000 | [diff] [blame] | 59 | return b? p : q; // expected-warning{{incompatible operand types ('void **' and 'const void **') use non-standard composite pointer type 'const void *const *'}} |
Douglas Gregor | b2cb1cb | 2010-02-25 22:29:57 +0000 | [diff] [blame] | 60 | } |