Add include needed for MSVC.
[clang/acc.git] / test / SemaCXX / overloaded-builtin-operators.cpp
blob2a6c24a6778ac0c76f5afe0d3d045df55935ec94
1 // RUN: clang-cc -fsyntax-only -verify %s
2 struct yes;
3 struct no;
5 struct Short {
6 operator short();
7 };
9 struct Long {
10 operator long();
13 enum E1 { };
14 struct Enum1 {
15 operator E1();
18 enum E2 { };
19 struct Enum2 {
20 operator E2();
23 yes& islong(long);
24 yes& islong(unsigned long); // FIXME: shouldn't be needed
25 no& islong(int);
27 void f(Short s, Long l, Enum1 e1, Enum2 e2) {
28 // C++ [over.built]p8
29 int i1 = +e1;
30 int i2 = -e2;
32 // C++ [over.built]p10:
33 int i3 = ~s;
34 bool b1 = !s;
36 // C++ [over.built]p12
37 (void)static_cast<yes&>(islong(s + l));
38 (void)static_cast<no&>(islong(s + s));
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));
44 (void)static_cast<yes&>(islong(e1 % l));
45 // FIXME: should pass (void)static_cast<no&>(islong(e1 % e2));
48 struct ShortRef {
49 operator short&();
52 struct LongRef {
53 operator volatile long&();
56 void g(ShortRef sr, LongRef lr) {
57 // C++ [over.built]p3
58 short s1 = sr++;
60 // C++ [over.built]p3
61 long l1 = lr--;
63 // C++ [over.built]p18
64 short& sr1 = (sr *= lr);
65 volatile long& lr1 = (lr *= sr);
67 // C++ [over.built]p22
68 short& sr2 = (sr %= lr);
69 volatile long& lr2 = (lr <<= sr);
71 bool b1 = (sr && lr) || (sr || lr);
74 struct VolatileIntPtr {
75 operator int volatile *();
78 struct ConstIntPtr {
79 operator int const *();
82 struct VolatileIntPtrRef {
83 operator int volatile *&();
86 struct ConstIntPtrRef {
87 operator int const *&();
90 void test_with_ptrs(VolatileIntPtr vip, ConstIntPtr cip, ShortRef sr,
91 VolatileIntPtrRef vipr, ConstIntPtrRef cipr) {
92 const int& cir1 = cip[sr];
93 const int& cir2 = sr[cip];
94 volatile int& vir1 = vip[sr];
95 volatile int& vir2 = sr[vip];
96 bool b1 = (vip == cip);
97 long p1 = vip - cip;
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;
105 // C++ [over.built]p6:
106 int volatile &ivr = *vip;
108 // C++ [over.built]p8:
109 int volatile *vip2 = +vip;
110 int i1 = +sr;
111 int i2 = -sr;
113 // C++ [over.built]p13:
114 int volatile &ivr2 = vip[17];
115 int const &icr2 = 17[cip];
118 // C++ [over.match.open]p4
120 void test_assign_restrictions(ShortRef& sr) {
121 sr = (short)0; // expected-error{{no viable overloaded '='}}