blob: 5989dc272639fe9c8c9035ac3e0838cdb16b6bb9 [file] [log] [blame]
Daniel Dunbard7d5f022009-03-24 02:24:46 +00001// RUN: clang-cc -fsyntax-only -verify %s
Douglas Gregoreb8f3062008-11-12 17:17:38 +00002struct yes;
3struct no;
4
5struct Short {
6 operator short();
7};
8
9struct Long {
10 operator long();
11};
12
Douglas Gregor447b69e2008-11-19 03:25:36 +000013enum E1 { };
14struct Enum1 {
15 operator E1();
16};
17
18enum E2 { };
19struct Enum2 {
20 operator E2();
21};
22
Douglas Gregoreb8f3062008-11-12 17:17:38 +000023yes& islong(long);
Douglas Gregor447b69e2008-11-19 03:25:36 +000024yes& islong(unsigned long); // FIXME: shouldn't be needed
Douglas Gregoreb8f3062008-11-12 17:17:38 +000025no& islong(int);
26
Douglas Gregor447b69e2008-11-19 03:25:36 +000027void f(Short s, Long l, Enum1 e1, Enum2 e2) {
Douglas Gregor74253732008-11-19 15:42:04 +000028 // 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 Gregoreb8f3062008-11-12 17:17:38 +000036 // 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 Gregor447b69e2008-11-19 03:25:36 +000044 (void)static_cast<yes&>(islong(e1 % l));
45 // FIXME: should pass (void)static_cast<no&>(islong(e1 % e2));
Douglas Gregoreb8f3062008-11-12 17:17:38 +000046}
47
48struct ShortRef {
49 operator short&();
50};
51
52struct LongRef {
53 operator volatile long&();
54};
55
56void g(ShortRef sr, LongRef lr) {
Douglas Gregor74253732008-11-19 15:42:04 +000057 // C++ [over.built]p3
58 short s1 = sr++;
59
60 // C++ [over.built]p3
61 long l1 = lr--;
62
Douglas Gregoreb8f3062008-11-12 17:17:38 +000063 // 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
74struct VolatileIntPtr {
75 operator int volatile *();
76};
77
78struct ConstIntPtr {
79 operator int const *();
80};
81
Douglas Gregor74253732008-11-19 15:42:04 +000082struct VolatileIntPtrRef {
83 operator int volatile *&();
84};
85
86struct ConstIntPtrRef {
87 operator int const *&();
88};
89
90void test_with_ptrs(VolatileIntPtr vip, ConstIntPtr cip, ShortRef sr,
91 VolatileIntPtrRef vipr, ConstIntPtrRef cipr) {
Douglas Gregoreb8f3062008-11-12 17:17:38 +000092 const int& cir1 = cip[sr];
93 const int& cir2 = sr[cip];
94 volatile int& vir1 = vip[sr];
95 volatile int& vir2 = sr[vip];
Douglas Gregoreb8f3062008-11-12 17:17:38 +000096 bool b1 = (vip == cip);
97 long p1 = vip - cip;
Douglas Gregor74253732008-11-19 15:42:04 +000098
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 Gregor337c6b92008-11-19 17:17:41 +0000112
113 // C++ [over.built]p13:
114 int volatile &ivr2 = vip[17];
115 int const &icr2 = 17[cip];
Douglas Gregoreb8f3062008-11-12 17:17:38 +0000116}
Douglas Gregor74253732008-11-19 15:42:04 +0000117
Douglas Gregor88b4bf22009-01-13 00:52:54 +0000118// C++ [over.match.open]p4
119
120void test_assign_restrictions(ShortRef& sr) {
121 sr = (short)0; // expected-error{{incompatible type assigning 'short', expected 'struct ShortRef'}}
122}