blob: af328da212bd84d8a1ebaaacd9cf76704bc8e287 [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 Gregor70d26122008-11-12 17:17:38 +000028 // 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 Gregor849ea9c2008-11-19 03:25:36 +000036 (void)static_cast<yes&>(islong(e1 % l));
37 // FIXME: should pass (void)static_cast<no&>(islong(e1 % e2));
Douglas Gregor70d26122008-11-12 17:17:38 +000038}
39
40struct ShortRef {
41 operator short&();
42};
43
44struct LongRef {
45 operator volatile long&();
46};
47
48void 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
60struct VolatileIntPtr {
61 operator int volatile *();
62};
63
64struct ConstIntPtr {
65 operator int const *();
66};
67
68void 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}