| 1 |
// RUN: %clang_cc1 -fsyntax-only -verify %s |
| 2 |
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s |
| 3 |
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s |
| 4 |
|
| 5 |
namespace A |
| 6 |
{ |
| 7 |
namespace B |
| 8 |
{ |
| 9 |
struct base |
| 10 |
#if __cplusplus <= 199711L |
| 11 |
// expected-note@-2 {{lookup in the object type 'A::sub' refers here}} |
| 12 |
#endif |
| 13 |
{ |
| 14 |
void x() {} |
| 15 |
void y() {} |
| 16 |
}; |
| 17 |
} |
| 18 |
|
| 19 |
struct member |
| 20 |
{ |
| 21 |
void foo(); |
| 22 |
}; |
| 23 |
|
| 24 |
struct middleman |
| 25 |
{ |
| 26 |
member * operator->() { return 0; } |
| 27 |
}; |
| 28 |
|
| 29 |
struct sub : B::base |
| 30 |
{ |
| 31 |
void x() {} |
| 32 |
middleman operator->() { return middleman(); } |
| 33 |
}; |
| 34 |
} |
| 35 |
|
| 36 |
struct bad |
| 37 |
{ |
| 38 |
int x(); |
| 39 |
}; |
| 40 |
|
| 41 |
namespace C |
| 42 |
{ |
| 43 |
void fun() |
| 44 |
{ |
| 45 |
A::sub a; |
| 46 |
|
| 47 |
a.x(); |
| 48 |
|
| 49 |
a.sub::x(); |
| 50 |
a.base::x(); |
| 51 |
|
| 52 |
a.B::base::x(); // expected-error{{use of undeclared identifier 'B'}} |
| 53 |
|
| 54 |
a.A::sub::x(); |
| 55 |
a.A::B::base::x(); |
| 56 |
|
| 57 |
a.bad::x(); // expected-error{{'bad::x' is not a member of class 'A::sub'}} |
| 58 |
|
| 59 |
a->foo(); |
| 60 |
a->member::foo(); |
| 61 |
a->A::member::foo(); |
| 62 |
} |
| 63 |
|
| 64 |
void fun2() |
| 65 |
{ |
| 66 |
A::sub *a; |
| 67 |
|
| 68 |
a->x(); |
| 69 |
|
| 70 |
a->sub::x(); |
| 71 |
a->base::x(); |
| 72 |
|
| 73 |
a->B::base::x(); // expected-error{{use of undeclared identifier 'B'}} |
| 74 |
|
| 75 |
a->A::sub::x(); |
| 76 |
a->A::B::base::x(); |
| 77 |
|
| 78 |
a->bad::x(); // expected-error{{'bad::x' is not a member of class 'A::sub'}} |
| 79 |
|
| 80 |
(*a)->foo(); |
| 81 |
(*a)->member::foo(); |
| 82 |
(*a)->A::member::foo(); |
| 83 |
} |
| 84 |
|
| 85 |
void fun3() |
| 86 |
{ |
| 87 |
int i; |
| 88 |
i.foo(); // expected-error{{member reference base type 'int' is not a structure or union}} |
| 89 |
} |
| 90 |
|
| 91 |
void fun4a() { |
| 92 |
A::sub *a; |
| 93 |
|
| 94 |
typedef A::member base; |
| 95 |
#if __cplusplus <= 199711L |
| 96 |
// expected-note@-2 {{lookup from the current scope refers here}} |
| 97 |
#endif |
| 98 |
a->base::x(); |
| 99 |
#if __cplusplus <= 199711L |
| 100 |
// expected-error@-2 {{lookup of 'base' in member access expression is ambiguous}} |
| 101 |
#endif |
| 102 |
} |
| 103 |
|
| 104 |
void fun4b() { |
| 105 |
A::sub *a; |
| 106 |
|
| 107 |
typedef A::B::base base; |
| 108 |
a->base::x(); |
| 109 |
} |
| 110 |
|
| 111 |
template<typename T> |
| 112 |
void fun5() |
| 113 |
{ |
| 114 |
T a; |
| 115 |
a.x(); |
| 116 |
a->foo(); |
| 117 |
|
| 118 |
a.A::sub::x(); |
| 119 |
a.A::B::base::x(); |
| 120 |
a->A::member::foo(); |
| 121 |
|
| 122 |
a.bad::x(); // expected-error{{'bad::x' is not a member of class 'A::sub'}} |
| 123 |
} |
| 124 |
|
| 125 |
void test_fun5() { |
| 126 |
fun5<A::sub>(); // expected-note{{instantiation}} |
| 127 |
} |
| 128 |
|
| 129 |
template<typename T> |
| 130 |
void fun6() { |
| 131 |
T a; |
| 132 |
a.sub::x(); |
| 133 |
a.base::x(); |
| 134 |
a->member::foo(); |
| 135 |
a.B::base::x(); // expected-error{{use of undeclared identifier 'B'}} |
| 136 |
} |
| 137 |
|
| 138 |
void test_fun6() { |
| 139 |
fun6<A::sub>(); // expected-note{{instantiation}} |
| 140 |
} |
| 141 |
|
| 142 |
} |
| 143 |
|
| 144 |
// PR4703 |
| 145 |
struct a { |
| 146 |
int a; |
| 147 |
static int sa; |
| 148 |
}; |
| 149 |
|
| 150 |
a a; |
| 151 |
|
| 152 |
int a::sa = a.a; // expected-error {{invalid use of non-static data member 'a'}} |
| 153 |
|
| 154 |
|
| 155 |
namespace PR6645 { |
| 156 |
typedef int foo; |
| 157 |
namespace Inner { |
| 158 |
typedef int PR6645::foo; // expected-error{{typedef declarator cannot be qualified}} \ |
| 159 |
// expected-error{{cannot define or redeclare 'foo' here because namespace 'Inner' does not enclose namespace 'PR6645'}} |
| 160 |
} |
| 161 |
} |