blob: e2462aa48d6d33895b381fc4881e5bb1d63bb1aa [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
Douglas Gregor86f19402008-12-20 23:49:58 +00002
3class X{
4public:
Douglas Gregorb0fd4832010-04-25 20:55:08 +00005 enum E {Enumerator}; // expected-note 2{{declared here}}
Douglas Gregor86f19402008-12-20 23:49:58 +00006 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();
Douglas Gregorb0fd4832010-04-25 20:55:08 +000014 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 '->'}}
Douglas Gregor76f7d282009-01-16 03:02:29 +000016 int i3 = x.Enumerator;
17 int i4 = xp->Enumerator;
Douglas Gregor86f19402008-12-20 23:49:58 +000018 x.mem = 1;
19 xp->mem = 2;
20 float f1 = x.g();
21 float f2 = xp->g();
22}
Douglas Gregor214f31a2009-03-27 06:00:30 +000023
24struct A {
25 int f0;
26};
27struct B {
28 A *f0();
29};
30int f0(B *b) {
John McCall6dbba4f2011-10-11 23:14:30 +000031 return b->f0->f0; // expected-error{{did you mean to call it with no arguments}}
Douglas Gregor214f31a2009-03-27 06:00:30 +000032}
Douglas Gregor8d1c9ae2009-10-17 22:37:54 +000033
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}
John McCallb1b42562009-12-01 22:28:41 +000044
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}
Douglas Gregor2b147f02010-04-25 21:15:30 +000059
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}
John McCallad00b772010-06-16 08:42:20 +000075
76namespace test5 {
77 struct A {
78 template <class T> void foo();
79 };
80
81 void test0(int x) {
John McCallad00b772010-06-16 08:42:20 +000082 }
83
84 void test1(A *x) {
John McCallad00b772010-06-16 08:42:20 +000085 }
86
87 void test2(A &x) {
Kaelyn Uhrainbaaeb852013-07-31 17:38:24 +000088 x->A::foo<int>(); // expected-error {{'test5::A' is not a pointer; maybe you meant to use '.'?}}
John McCallad00b772010-06-16 08:42:20 +000089 }
90}
Douglas Gregor12eb5d62010-06-29 19:27:42 +000091
92namespace PR7508 {
93 struct A {
94 struct CleanupScope {};
Kaelyn Uhraine4c7f902012-01-13 21:28:55 +000095 void PopCleanupBlock(); // expected-note{{'PopCleanupBlock' declared here}}
Douglas Gregor12eb5d62010-06-29 19:27:42 +000096 };
97
98 void foo(A &a) {
Kaelyn Uhraine4c7f902012-01-13 21:28:55 +000099 a.PopCleanupScope(); // expected-error{{no member named 'PopCleanupScope' in 'PR7508::A'; did you mean 'PopCleanupBlock'?}}
Douglas Gregor12eb5d62010-06-29 19:27:42 +0000100 }
101}
Douglas Gregor9d4bb942010-07-28 22:27:52 +0000102
103namespace rdar8231724 {
104 namespace N {
105 template<typename T> struct X1;
106 int i;
107 }
108
109 struct X { };
110 struct Y : X { };
111
Richard Smithd6537012012-11-15 00:31:27 +0000112 template<typename T> struct Z { int n; };
113
Douglas Gregor9d4bb942010-07-28 22:27:52 +0000114 void f(Y *y) {
115 y->N::X1<int>; // expected-error{{'rdar8231724::N::X1' is not a member of class 'rdar8231724::Y'}}
Richard Smithd6537012012-11-15 00:31:27 +0000116 y->Z<int>::n; // expected-error{{'rdar8231724::Z<int>::n' is not a member of class 'rdar8231724::Y'}}
117 y->template Z<int>::n; // expected-error{{'rdar8231724::Z<int>::n' is not a member of class 'rdar8231724::Y'}} \
118 // expected-warning{{'template' keyword outside of a template}}
Douglas Gregor9d4bb942010-07-28 22:27:52 +0000119 }
120}
Matt Beaumont-Gay26ae5dd2011-02-17 02:54:17 +0000121
122namespace PR9025 {
123 struct S { int x; };
John McCall6dbba4f2011-10-11 23:14:30 +0000124 S fun(); // expected-note{{possible target for call}}
125 int fun(int i); // expected-note{{possible target for call}}
Matt Beaumont-Gay26ae5dd2011-02-17 02:54:17 +0000126 int g() {
John McCall6dbba4f2011-10-11 23:14:30 +0000127 return fun.x; // expected-error{{reference to overloaded function could not be resolved; did you mean to call it with no arguments?}}
Matt Beaumont-Gay26ae5dd2011-02-17 02:54:17 +0000128 }
129
John McCall6dbba4f2011-10-11 23:14:30 +0000130 S fun2(); // expected-note{{possible target for call}}
131 S fun2(int i); // expected-note{{possible target for call}}
Matt Beaumont-Gay26ae5dd2011-02-17 02:54:17 +0000132 int g2() {
John McCall6dbba4f2011-10-11 23:14:30 +0000133 return fun2.x; // expected-error{{reference to overloaded function could not be resolved; did you mean to call it with no arguments?}}
Matt Beaumont-Gay26ae5dd2011-02-17 02:54:17 +0000134 }
Matt Beaumont-Gay65b34d72011-02-22 23:52:53 +0000135
John McCall6dbba4f2011-10-11 23:14:30 +0000136 S fun3(int i=0); // expected-note{{possible target for call}}
137 int fun3(int i, int j); // expected-note{{possible target for call}}
Matt Beaumont-Gay65b34d72011-02-22 23:52:53 +0000138 int g3() {
John McCall6dbba4f2011-10-11 23:14:30 +0000139 return fun3.x; // expected-error{{reference to overloaded function could not be resolved; did you mean to call it with no arguments?}}
Matt Beaumont-Gay65b34d72011-02-22 23:52:53 +0000140 }
Matt Beaumont-Gayfbe59942011-03-05 02:42:30 +0000141
John McCall6dbba4f2011-10-11 23:14:30 +0000142 template <typename T> S fun4(); // expected-note{{possible target for call}}
Matt Beaumont-Gayfbe59942011-03-05 02:42:30 +0000143 int g4() {
John McCall6dbba4f2011-10-11 23:14:30 +0000144 return fun4.x; // expected-error{{reference to overloaded function could not be resolved; did you mean to call it?}}
Matt Beaumont-Gayfbe59942011-03-05 02:42:30 +0000145 }
Matt Beaumont-Gayc9366ba2011-05-04 22:10:40 +0000146
John McCall6dbba4f2011-10-11 23:14:30 +0000147 S fun5(int i); // expected-note{{possible target for call}}
148 S fun5(float f); // expected-note{{possible target for call}}
Matt Beaumont-Gayc9366ba2011-05-04 22:10:40 +0000149 int g5() {
John McCall6dbba4f2011-10-11 23:14:30 +0000150 return fun5.x; // expected-error{{reference to overloaded function could not be resolved; did you mean to call it?}}
Matt Beaumont-Gayc9366ba2011-05-04 22:10:40 +0000151 }
Matt Beaumont-Gay26ae5dd2011-02-17 02:54:17 +0000152}
Eli Friedman059d5782012-01-13 02:20:01 +0000153
154namespace FuncInMemberExpr {
155 struct Vec { int size(); };
156 Vec fun1();
157 int test1() { return fun1.size(); } // expected-error {{base of member reference is a function; perhaps you meant to call it with no arguments}}
158 Vec *fun2();
159 int test2() { return fun2->size(); } // expected-error {{base of member reference is a function; perhaps you meant to call it with no arguments}}
160 Vec fun3(int x = 0);
161 int test3() { return fun3.size(); } // expected-error {{base of member reference is a function; perhaps you meant to call it with no arguments}}
162}
Matt Beaumont-Gay7d90fe52012-04-21 01:12:48 +0000163
164namespace DotForSemiTypo {
165void f(int i) {
166 // If the programmer typo'd '.' for ';', make sure we point at the '.' rather
167 // than the "field name" (whatever the first token on the next line happens to
168 // be).
169 int j = i. // expected-error {{member reference base type 'int' is not a structure or union}}
170 j = 0;
171}
172}
Kaelyn Uhraind4224342013-07-15 19:54:54 +0000173
174namespace PR15045 {
175 class Cl0 {
176 public:
177 int a;
178 };
179
180 int f() {
181 Cl0 c;
Kaelyn Uhrainbaaeb852013-07-31 17:38:24 +0000182 return c->a; // expected-error {{member reference type 'PR15045::Cl0' is not a pointer; maybe you meant to use '.'?}}
183 }
184
185 struct bar {
186 void func(); // expected-note {{'func' declared here}}
187 };
188
189 struct foo {
190 bar operator->(); // expected-note 2 {{'->' applied to return value of the operator->() declared here}}
191 };
192
193 template <class T> void call_func(T t) {
194 t->func(); // expected-error-re 2 {{member reference type 'PR15045::bar' is not a pointer$}} \
195 // expected-note {{did you mean to use '.' instead?}}
196 }
197
198 void test_arrow_on_non_pointer_records() {
199 bar e;
200 foo f;
201
202 // Show that recovery has happened by also triggering typo correction
203 e->Func(); // expected-error {{member reference type 'PR15045::bar' is not a pointer; maybe you meant to use '.'?}} \
204 // expected-error {{no member named 'Func' in 'PR15045::bar'; did you mean 'func'?}}
205
206 // Make sure a fixit isn't given in the case that the '->' isn't actually
207 // the problem (the problem is with the return value of an operator->).
208 f->func(); // expected-error-re {{member reference type 'PR15045::bar' is not a pointer$}}
209
210 call_func(e); // expected-note {{in instantiation of function template specialization 'PR15045::call_func<PR15045::bar>' requested here}}
211
212 call_func(f); // expected-note {{in instantiation of function template specialization 'PR15045::call_func<PR15045::foo>' requested here}}
Kaelyn Uhraind4224342013-07-15 19:54:54 +0000213 }
214}