member-expr.cpp revision c14e6dda1e1287d3e0aeaa0e8f7bb2c9126f312c
1// RUN: %clang_cc1 -fsyntax-only -verify %s 2 3class X{ 4public: 5 enum E {Enumerator}; // expected-note 2{{declared here}} 6 int f(); 7 static int mem; 8 static float g(); 9}; 10 11void test(X* xp, X x) { 12 int i1 = x.f(); 13 int i2 = xp->f(); 14 x.E; // expected-error{{cannot refer to type member 'E' in 'X' with '.'}} 15 xp->E; // expected-error{{cannot refer to type member 'E' in 'X' with '->'}} 16 int i3 = x.Enumerator; 17 int i4 = xp->Enumerator; 18 x.mem = 1; 19 xp->mem = 2; 20 float f1 = x.g(); 21 float f2 = xp->g(); 22} 23 24struct A { 25 int f0; 26}; 27struct B { 28 A *f0(); 29}; 30int f0(B *b) { 31 return b->f0->f0; // expected-error{{did you mean to call it with no arguments}} 32} 33 34int i; 35 36namespace C { 37 int i; 38} 39 40void test2(X *xp) { 41 xp->::i = 7; // expected-error{{qualified member access refers to a member in the global namespace}} 42 xp->C::i = 7; // expected-error{{qualified member access refers to a member in namespace 'C'}} 43} 44 45 46namespace test3 { 47 struct NamespaceDecl; 48 49 struct NamedDecl { 50 void *getIdentifier() const; 51 }; 52 53 struct NamespaceDecl : NamedDecl { 54 bool isAnonymousNamespace() const { 55 return !getIdentifier(); 56 } 57 }; 58} 59 60namespace test4 { 61 class X { 62 protected: 63 template<typename T> void f(T); 64 }; 65 66 class Y : public X { 67 public: 68 using X::f; 69 }; 70 71 void test_f(Y y) { 72 y.f(17); 73 } 74} 75 76namespace test5 { 77 struct A { 78 template <class T> void foo(); 79 }; 80 81 void test0(int x) { 82 x.A::foo<int>(); // expected-error {{'int' is not a structure or union}} 83 } 84 85 void test1(A *x) { 86 x.A::foo<int>(); // expected-error {{'test5::A *' is a pointer}} 87 } 88 89 void test2(A &x) { 90 x->A::foo<int>(); // expected-error {{'test5::A' is not a pointer; maybe you meant to use '.'?}} 91 } 92} 93 94namespace PR7508 { 95 struct A { 96 struct CleanupScope {}; 97 void PopCleanupBlock(); // expected-note{{'PopCleanupBlock' declared here}} 98 }; 99 100 void foo(A &a) { 101 a.PopCleanupScope(); // expected-error{{no member named 'PopCleanupScope' in 'PR7508::A'; did you mean 'PopCleanupBlock'?}} 102 } 103} 104 105namespace rdar8231724 { 106 namespace N { 107 template<typename T> struct X1; 108 int i; 109 } 110 111 struct X { }; 112 struct Y : X { }; 113 114 template<typename T> struct Z { int n; }; 115 116 void f(Y *y) { 117 y->N::X1<int>; // expected-error{{'rdar8231724::N::X1' is not a member of class 'rdar8231724::Y'}} 118 y->Z<int>::n; // expected-error{{'rdar8231724::Z<int>::n' is not a member of class 'rdar8231724::Y'}} 119 y->template Z<int>::n; // expected-error{{'rdar8231724::Z<int>::n' is not a member of class 'rdar8231724::Y'}} \ 120 // expected-warning{{'template' keyword outside of a template}} 121 } 122} 123 124namespace PR9025 { 125 struct S { int x; }; 126 S fun(); // expected-note{{possible target for call}} 127 int fun(int i); // expected-note{{possible target for call}} 128 int g() { 129 return fun.x; // expected-error{{reference to overloaded function could not be resolved; did you mean to call it with no arguments?}} 130 } 131 132 S fun2(); // expected-note{{possible target for call}} 133 S fun2(int i); // expected-note{{possible target for call}} 134 int g2() { 135 return fun2.x; // expected-error{{reference to overloaded function could not be resolved; did you mean to call it with no arguments?}} 136 } 137 138 S fun3(int i=0); // expected-note{{possible target for call}} 139 int fun3(int i, int j); // expected-note{{possible target for call}} 140 int g3() { 141 return fun3.x; // expected-error{{reference to overloaded function could not be resolved; did you mean to call it with no arguments?}} 142 } 143 144 template <typename T> S fun4(); // expected-note{{possible target for call}} 145 int g4() { 146 return fun4.x; // expected-error{{reference to overloaded function could not be resolved; did you mean to call it?}} 147 } 148 149 S fun5(int i); // expected-note{{possible target for call}} 150 S fun5(float f); // expected-note{{possible target for call}} 151 int g5() { 152 return fun5.x; // expected-error{{reference to overloaded function could not be resolved; did you mean to call it?}} 153 } 154} 155 156namespace FuncInMemberExpr { 157 struct Vec { int size(); }; 158 Vec fun1(); 159 int test1() { return fun1.size(); } // expected-error {{base of member reference is a function; perhaps you meant to call it with no arguments}} 160 Vec *fun2(); 161 int test2() { return fun2->size(); } // expected-error {{base of member reference is a function; perhaps you meant to call it with no arguments}} 162 Vec fun3(int x = 0); 163 int test3() { return fun3.size(); } // expected-error {{base of member reference is a function; perhaps you meant to call it with no arguments}} 164} 165 166namespace DotForSemiTypo { 167void f(int i) { 168 // If the programmer typo'd '.' for ';', make sure we point at the '.' rather 169 // than the "field name" (whatever the first token on the next line happens to 170 // be). 171 int j = i. // expected-error {{member reference base type 'int' is not a structure or union}} 172 j = 0; 173} 174} 175 176namespace PR15045 { 177 class Cl0 { 178 public: 179 int a; 180 }; 181 182 int f() { 183 Cl0 c; 184 return c->a; // expected-error {{member reference type 'PR15045::Cl0' is not a pointer; maybe you meant to use '.'?}} 185 } 186 187 struct bar { 188 void func(); // expected-note {{'func' declared here}} 189 }; 190 191 struct foo { 192 bar operator->(); // expected-note 2 {{'->' applied to return value of the operator->() declared here}} 193 }; 194 195 template <class T> void call_func(T t) { 196 t->func(); // expected-error-re 2 {{member reference type 'PR15045::bar' is not a pointer$}} \ 197 // expected-note {{did you mean to use '.' instead?}} 198 } 199 200 void test_arrow_on_non_pointer_records() { 201 bar e; 202 foo f; 203 204 // Show that recovery has happened by also triggering typo correction 205 e->Func(); // expected-error {{member reference type 'PR15045::bar' is not a pointer; maybe you meant to use '.'?}} \ 206 // expected-error {{no member named 'Func' in 'PR15045::bar'; did you mean 'func'?}} 207 208 // Make sure a fixit isn't given in the case that the '->' isn't actually 209 // the problem (the problem is with the return value of an operator->). 210 f->func(); // expected-error-re {{member reference type 'PR15045::bar' is not a pointer$}} 211 212 call_func(e); // expected-note {{in instantiation of function template specialization 'PR15045::call_func<PR15045::bar>' requested here}} 213 214 call_func(f); // expected-note {{in instantiation of function template specialization 'PR15045::call_func<PR15045::foo>' requested here}} 215 } 216} 217