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 | |
Douglas Gregor | 849ea9c | 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 | 70d2612 | 2008-11-12 17:17:38 +0000 | [diff] [blame] | 23 | yes& islong(long); |
Douglas Gregor | 849ea9c | 2008-11-19 03:25:36 +0000 | [diff] [blame^] | 24 | yes& islong(unsigned long); // FIXME: shouldn't be needed |
Douglas Gregor | 70d2612 | 2008-11-12 17:17:38 +0000 | [diff] [blame] | 25 | no& islong(int); |
| 26 | |
Douglas Gregor | 849ea9c | 2008-11-19 03:25:36 +0000 | [diff] [blame^] | 27 | void f(Short s, Long l, Enum1 e1, Enum2 e2) { |
Douglas Gregor | 70d2612 | 2008-11-12 17:17:38 +0000 | [diff] [blame] | 28 | // C++ [over.built]p12 |
| 29 | (void)static_cast<yes&>(islong(s + l)); |
| 30 | (void)static_cast<no&>(islong(s + s)); |
| 31 | |
| 32 | // C++ [over.built]p17 |
| 33 | (void)static_cast<yes&>(islong(s % l)); |
| 34 | (void)static_cast<yes&>(islong(l << s)); |
| 35 | (void)static_cast<no&>(islong(s << l)); |
Douglas Gregor | 849ea9c | 2008-11-19 03:25:36 +0000 | [diff] [blame^] | 36 | (void)static_cast<yes&>(islong(e1 % l)); |
| 37 | // FIXME: should pass (void)static_cast<no&>(islong(e1 % e2)); |
Douglas Gregor | 70d2612 | 2008-11-12 17:17:38 +0000 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | struct ShortRef { |
| 41 | operator short&(); |
| 42 | }; |
| 43 | |
| 44 | struct LongRef { |
| 45 | operator volatile long&(); |
| 46 | }; |
| 47 | |
| 48 | void g(ShortRef sr, LongRef lr) { |
| 49 | // C++ [over.built]p18 |
| 50 | short& sr1 = (sr *= lr); |
| 51 | volatile long& lr1 = (lr *= sr); |
| 52 | |
| 53 | // C++ [over.built]p22 |
| 54 | short& sr2 = (sr %= lr); |
| 55 | volatile long& lr2 = (lr <<= sr); |
| 56 | |
| 57 | bool b1 = (sr && lr) || (sr || lr); |
| 58 | } |
| 59 | |
| 60 | struct VolatileIntPtr { |
| 61 | operator int volatile *(); |
| 62 | }; |
| 63 | |
| 64 | struct ConstIntPtr { |
| 65 | operator int const *(); |
| 66 | }; |
| 67 | |
| 68 | void test_with_ptrs(VolatileIntPtr vip, ConstIntPtr cip, ShortRef sr) { |
| 69 | #if 0 |
| 70 | // FIXME: Enable these tests once we have operator overloading for |
| 71 | // operator[]. |
| 72 | const int& cir1 = cip[sr]; |
| 73 | const int& cir2 = sr[cip]; |
| 74 | volatile int& vir1 = vip[sr]; |
| 75 | volatile int& vir2 = sr[vip]; |
| 76 | #endif |
| 77 | bool b1 = (vip == cip); |
| 78 | long p1 = vip - cip; |
| 79 | } |