blob: 29d721c45bbf059bdb504c81f67754e3d530f704 [file] [log] [blame]
Douglas Gregor70d26122008-11-12 17:17:38 +00001// RUN: clang -fsyntax-only -verify %s
2struct yes;
3struct no;
4
5struct Short {
6 operator short();
7};
8
9struct Long {
10 operator long();
11};
12
Douglas Gregor849ea9c2008-11-19 03:25:36 +000013enum E1 { };
14struct Enum1 {
15 operator E1();
16};
17
18enum E2 { };
19struct Enum2 {
20 operator E2();
21};
22
Douglas Gregor70d26122008-11-12 17:17:38 +000023yes& islong(long);
Douglas Gregor849ea9c2008-11-19 03:25:36 +000024yes& islong(unsigned long); // FIXME: shouldn't be needed
Douglas Gregor70d26122008-11-12 17:17:38 +000025no& islong(int);
26
Douglas Gregor849ea9c2008-11-19 03:25:36 +000027void f(Short s, Long l, Enum1 e1, Enum2 e2) {
Douglas Gregor4f6904d2008-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 Gregor70d26122008-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 Gregor849ea9c2008-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 Gregor70d26122008-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 Gregor4f6904d2008-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 Gregor70d26122008-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 Gregor4f6904d2008-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 Gregor70d26122008-11-12 17:17:38 +000092#if 0
93 // FIXME: Enable these tests once we have operator overloading for
94 // operator[].
95 const int& cir1 = cip[sr];
96 const int& cir2 = sr[cip];
97 volatile int& vir1 = vip[sr];
98 volatile int& vir2 = sr[vip];
99#endif
100 bool b1 = (vip == cip);
101 long p1 = vip - cip;
Douglas Gregor4f6904d2008-11-19 15:42:04 +0000102
103 // C++ [over.built]p5:
104 int volatile *vip1 = vipr++;
105 int const *cip1 = cipr++;
106 int volatile *&vipr1 = ++vipr;
107 int const *&cipr1 = --cipr;
108
109 // C++ [over.built]p6:
110 int volatile &ivr = *vip;
111
112 // C++ [over.built]p8:
113 int volatile *vip2 = +vip;
114 int i1 = +sr;
115 int i2 = -sr;
Douglas Gregor70d26122008-11-12 17:17:38 +0000116}
Douglas Gregor4f6904d2008-11-19 15:42:04 +0000117