Douglas Gregor | 70d2612 | 2008-11-12 17:17:38 +0000 | [diff] [blame] | 1 | // RUN: clang -fsyntax-only -verify %s |
| 2 | struct yes; |
| 3 | struct no; |
| 4 | |
| 5 | struct Short { |
| 6 | operator short(); |
| 7 | }; |
| 8 | |
| 9 | struct Long { |
| 10 | operator long(); |
| 11 | }; |
| 12 | |
| 13 | yes& islong(long); |
| 14 | no& islong(int); |
| 15 | |
| 16 | void f(Short s, Long l) { |
| 17 | // C++ [over.built]p12 |
| 18 | (void)static_cast<yes&>(islong(s + l)); |
| 19 | (void)static_cast<no&>(islong(s + s)); |
| 20 | |
| 21 | // C++ [over.built]p17 |
| 22 | (void)static_cast<yes&>(islong(s % l)); |
| 23 | (void)static_cast<yes&>(islong(l << s)); |
| 24 | (void)static_cast<no&>(islong(s << l)); |
| 25 | } |
| 26 | |
| 27 | struct ShortRef { |
| 28 | operator short&(); |
| 29 | }; |
| 30 | |
| 31 | struct LongRef { |
| 32 | operator volatile long&(); |
| 33 | }; |
| 34 | |
| 35 | void g(ShortRef sr, LongRef lr) { |
| 36 | // C++ [over.built]p18 |
| 37 | short& sr1 = (sr *= lr); |
| 38 | volatile long& lr1 = (lr *= sr); |
| 39 | |
| 40 | // C++ [over.built]p22 |
| 41 | short& sr2 = (sr %= lr); |
| 42 | volatile long& lr2 = (lr <<= sr); |
| 43 | |
| 44 | bool b1 = (sr && lr) || (sr || lr); |
| 45 | } |
| 46 | |
| 47 | struct VolatileIntPtr { |
| 48 | operator int volatile *(); |
| 49 | }; |
| 50 | |
| 51 | struct ConstIntPtr { |
| 52 | operator int const *(); |
| 53 | }; |
| 54 | |
| 55 | void test_with_ptrs(VolatileIntPtr vip, ConstIntPtr cip, ShortRef sr) { |
| 56 | #if 0 |
| 57 | // FIXME: Enable these tests once we have operator overloading for |
| 58 | // operator[]. |
| 59 | const int& cir1 = cip[sr]; |
| 60 | const int& cir2 = sr[cip]; |
| 61 | volatile int& vir1 = vip[sr]; |
| 62 | volatile int& vir2 = sr[vip]; |
| 63 | #endif |
| 64 | bool b1 = (vip == cip); |
| 65 | long p1 = vip - cip; |
| 66 | } |