Daniel Dunbar | d7d5f02 | 2009-03-24 02:24:46 +0000 | [diff] [blame] | 1 | // RUN: clang-cc -fsyntax-only -verify %s |
Douglas Gregor | eb8f306 | 2008-11-12 17:17:38 +0000 | [diff] [blame] | 2 | struct yes; |
| 3 | struct no; |
| 4 | |
| 5 | struct Short { |
| 6 | operator short(); |
| 7 | }; |
| 8 | |
| 9 | struct Long { |
| 10 | operator long(); |
| 11 | }; |
| 12 | |
Douglas Gregor | 447b69e | 2008-11-19 03:25:36 +0000 | [diff] [blame] | 13 | enum E1 { }; |
| 14 | struct Enum1 { |
| 15 | operator E1(); |
| 16 | }; |
| 17 | |
| 18 | enum E2 { }; |
| 19 | struct Enum2 { |
| 20 | operator E2(); |
| 21 | }; |
| 22 | |
Douglas Gregor | eb8f306 | 2008-11-12 17:17:38 +0000 | [diff] [blame] | 23 | yes& islong(long); |
Douglas Gregor | 447b69e | 2008-11-19 03:25:36 +0000 | [diff] [blame] | 24 | yes& islong(unsigned long); // FIXME: shouldn't be needed |
Douglas Gregor | eb8f306 | 2008-11-12 17:17:38 +0000 | [diff] [blame] | 25 | no& islong(int); |
| 26 | |
Douglas Gregor | 447b69e | 2008-11-19 03:25:36 +0000 | [diff] [blame] | 27 | void f(Short s, Long l, Enum1 e1, Enum2 e2) { |
Douglas Gregor | 7425373 | 2008-11-19 15:42:04 +0000 | [diff] [blame] | 28 | // C++ [over.built]p8 |
| 29 | int i1 = +e1; |
| 30 | int i2 = -e2; |
| 31 | |
| 32 | // C++ [over.built]p10: |
| 33 | int i3 = ~s; |
| 34 | bool b1 = !s; |
| 35 | |
Douglas Gregor | eb8f306 | 2008-11-12 17:17:38 +0000 | [diff] [blame] | 36 | // C++ [over.built]p12 |
| 37 | (void)static_cast<yes&>(islong(s + l)); |
| 38 | (void)static_cast<no&>(islong(s + s)); |
| 39 | |
| 40 | // C++ [over.built]p17 |
| 41 | (void)static_cast<yes&>(islong(s % l)); |
| 42 | (void)static_cast<yes&>(islong(l << s)); |
| 43 | (void)static_cast<no&>(islong(s << l)); |
Douglas Gregor | 447b69e | 2008-11-19 03:25:36 +0000 | [diff] [blame] | 44 | (void)static_cast<yes&>(islong(e1 % l)); |
| 45 | // FIXME: should pass (void)static_cast<no&>(islong(e1 % e2)); |
Douglas Gregor | eb8f306 | 2008-11-12 17:17:38 +0000 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | struct ShortRef { |
| 49 | operator short&(); |
| 50 | }; |
| 51 | |
| 52 | struct LongRef { |
| 53 | operator volatile long&(); |
| 54 | }; |
| 55 | |
| 56 | void g(ShortRef sr, LongRef lr) { |
Douglas Gregor | 7425373 | 2008-11-19 15:42:04 +0000 | [diff] [blame] | 57 | // C++ [over.built]p3 |
| 58 | short s1 = sr++; |
| 59 | |
| 60 | // C++ [over.built]p3 |
| 61 | long l1 = lr--; |
| 62 | |
Douglas Gregor | eb8f306 | 2008-11-12 17:17:38 +0000 | [diff] [blame] | 63 | // C++ [over.built]p18 |
| 64 | short& sr1 = (sr *= lr); |
| 65 | volatile long& lr1 = (lr *= sr); |
| 66 | |
| 67 | // C++ [over.built]p22 |
| 68 | short& sr2 = (sr %= lr); |
| 69 | volatile long& lr2 = (lr <<= sr); |
| 70 | |
| 71 | bool b1 = (sr && lr) || (sr || lr); |
| 72 | } |
| 73 | |
| 74 | struct VolatileIntPtr { |
| 75 | operator int volatile *(); |
| 76 | }; |
| 77 | |
| 78 | struct ConstIntPtr { |
| 79 | operator int const *(); |
| 80 | }; |
| 81 | |
Douglas Gregor | 7425373 | 2008-11-19 15:42:04 +0000 | [diff] [blame] | 82 | struct VolatileIntPtrRef { |
| 83 | operator int volatile *&(); |
| 84 | }; |
| 85 | |
| 86 | struct ConstIntPtrRef { |
| 87 | operator int const *&(); |
| 88 | }; |
| 89 | |
| 90 | void test_with_ptrs(VolatileIntPtr vip, ConstIntPtr cip, ShortRef sr, |
| 91 | VolatileIntPtrRef vipr, ConstIntPtrRef cipr) { |
Douglas Gregor | eb8f306 | 2008-11-12 17:17:38 +0000 | [diff] [blame] | 92 | const int& cir1 = cip[sr]; |
| 93 | const int& cir2 = sr[cip]; |
| 94 | volatile int& vir1 = vip[sr]; |
| 95 | volatile int& vir2 = sr[vip]; |
Douglas Gregor | eb8f306 | 2008-11-12 17:17:38 +0000 | [diff] [blame] | 96 | bool b1 = (vip == cip); |
| 97 | long p1 = vip - cip; |
Douglas Gregor | 7425373 | 2008-11-19 15:42:04 +0000 | [diff] [blame] | 98 | |
| 99 | // C++ [over.built]p5: |
| 100 | int volatile *vip1 = vipr++; |
| 101 | int const *cip1 = cipr++; |
| 102 | int volatile *&vipr1 = ++vipr; |
| 103 | int const *&cipr1 = --cipr; |
| 104 | |
| 105 | // C++ [over.built]p6: |
| 106 | int volatile &ivr = *vip; |
| 107 | |
| 108 | // C++ [over.built]p8: |
| 109 | int volatile *vip2 = +vip; |
| 110 | int i1 = +sr; |
| 111 | int i2 = -sr; |
Douglas Gregor | 337c6b9 | 2008-11-19 17:17:41 +0000 | [diff] [blame] | 112 | |
| 113 | // C++ [over.built]p13: |
| 114 | int volatile &ivr2 = vip[17]; |
| 115 | int const &icr2 = 17[cip]; |
Douglas Gregor | eb8f306 | 2008-11-12 17:17:38 +0000 | [diff] [blame] | 116 | } |
Douglas Gregor | 7425373 | 2008-11-19 15:42:04 +0000 | [diff] [blame] | 117 | |
Douglas Gregor | 88b4bf2 | 2009-01-13 00:52:54 +0000 | [diff] [blame] | 118 | // C++ [over.match.open]p4 |
| 119 | |
| 120 | void test_assign_restrictions(ShortRef& sr) { |
| 121 | sr = (short)0; // expected-error{{incompatible type assigning 'short', expected 'struct ShortRef'}} |
| 122 | } |