2009-12-16 04:14:24 +08:00
|
|
|
// RUN: %clang_cc1 -fsyntax-only -verify %s
|
2015-11-12 03:34:47 +08:00
|
|
|
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s
|
|
|
|
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
|
2008-12-21 07:49:58 +08:00
|
|
|
|
|
|
|
class X{
|
|
|
|
public:
|
2010-04-26 04:55:08 +08:00
|
|
|
enum E {Enumerator}; // expected-note 2{{declared here}}
|
2008-12-21 07:49:58 +08:00
|
|
|
int f();
|
|
|
|
static int mem;
|
|
|
|
static float g();
|
|
|
|
};
|
|
|
|
|
|
|
|
void test(X* xp, X x) {
|
|
|
|
int i1 = x.f();
|
|
|
|
int i2 = xp->f();
|
2010-04-26 04:55:08 +08:00
|
|
|
x.E; // expected-error{{cannot refer to type member 'E' in 'X' with '.'}}
|
|
|
|
xp->E; // expected-error{{cannot refer to type member 'E' in 'X' with '->'}}
|
2009-01-16 11:02:29 +08:00
|
|
|
int i3 = x.Enumerator;
|
|
|
|
int i4 = xp->Enumerator;
|
2008-12-21 07:49:58 +08:00
|
|
|
x.mem = 1;
|
|
|
|
xp->mem = 2;
|
|
|
|
float f1 = x.g();
|
|
|
|
float f2 = xp->g();
|
|
|
|
}
|
2009-03-27 14:00:30 +08:00
|
|
|
|
|
|
|
struct A {
|
|
|
|
int f0;
|
|
|
|
};
|
|
|
|
struct B {
|
|
|
|
A *f0();
|
|
|
|
};
|
|
|
|
int f0(B *b) {
|
2011-10-12 07:14:30 +08:00
|
|
|
return b->f0->f0; // expected-error{{did you mean to call it with no arguments}}
|
2009-03-27 14:00:30 +08:00
|
|
|
}
|
2009-10-18 06:37:54 +08:00
|
|
|
|
|
|
|
int i;
|
|
|
|
|
|
|
|
namespace C {
|
|
|
|
int i;
|
|
|
|
}
|
|
|
|
|
|
|
|
void test2(X *xp) {
|
|
|
|
xp->::i = 7; // expected-error{{qualified member access refers to a member in the global namespace}}
|
|
|
|
xp->C::i = 7; // expected-error{{qualified member access refers to a member in namespace 'C'}}
|
|
|
|
}
|
2009-12-02 06:28:41 +08:00
|
|
|
|
|
|
|
|
|
|
|
namespace test3 {
|
|
|
|
struct NamespaceDecl;
|
|
|
|
|
|
|
|
struct NamedDecl {
|
|
|
|
void *getIdentifier() const;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct NamespaceDecl : NamedDecl {
|
|
|
|
bool isAnonymousNamespace() const {
|
|
|
|
return !getIdentifier();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2010-04-26 05:15:30 +08:00
|
|
|
|
|
|
|
namespace test4 {
|
|
|
|
class X {
|
|
|
|
protected:
|
|
|
|
template<typename T> void f(T);
|
|
|
|
};
|
|
|
|
|
|
|
|
class Y : public X {
|
|
|
|
public:
|
|
|
|
using X::f;
|
|
|
|
};
|
|
|
|
|
|
|
|
void test_f(Y y) {
|
|
|
|
y.f(17);
|
|
|
|
}
|
|
|
|
}
|
2010-06-16 16:42:20 +08:00
|
|
|
|
|
|
|
namespace test5 {
|
|
|
|
struct A {
|
|
|
|
template <class T> void foo();
|
|
|
|
};
|
|
|
|
|
|
|
|
void test0(int x) {
|
2013-08-01 04:16:17 +08:00
|
|
|
x.A::foo<int>(); // expected-error {{'int' is not a structure or union}}
|
2010-06-16 16:42:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void test1(A *x) {
|
2013-08-01 04:16:17 +08:00
|
|
|
x.A::foo<int>(); // expected-error {{'test5::A *' is a pointer}}
|
2010-06-16 16:42:20 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void test2(A &x) {
|
2015-04-03 06:10:06 +08:00
|
|
|
x->A::foo<int>(); // expected-error {{'test5::A' is not a pointer; did you mean to use '.'?}}
|
2010-06-16 16:42:20 +08:00
|
|
|
}
|
|
|
|
}
|
2010-06-30 03:27:42 +08:00
|
|
|
|
|
|
|
namespace PR7508 {
|
|
|
|
struct A {
|
|
|
|
struct CleanupScope {};
|
2012-01-14 05:28:55 +08:00
|
|
|
void PopCleanupBlock(); // expected-note{{'PopCleanupBlock' declared here}}
|
2010-06-30 03:27:42 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
void foo(A &a) {
|
2012-01-14 05:28:55 +08:00
|
|
|
a.PopCleanupScope(); // expected-error{{no member named 'PopCleanupScope' in 'PR7508::A'; did you mean 'PopCleanupBlock'?}}
|
2010-06-30 03:27:42 +08:00
|
|
|
}
|
|
|
|
}
|
2010-07-29 06:27:52 +08:00
|
|
|
|
|
|
|
namespace rdar8231724 {
|
|
|
|
namespace N {
|
|
|
|
template<typename T> struct X1;
|
|
|
|
int i;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct X { };
|
|
|
|
struct Y : X { };
|
|
|
|
|
2012-11-15 08:31:27 +08:00
|
|
|
template<typename T> struct Z { int n; };
|
|
|
|
|
2010-07-29 06:27:52 +08:00
|
|
|
void f(Y *y) {
|
|
|
|
y->N::X1<int>; // expected-error{{'rdar8231724::N::X1' is not a member of class 'rdar8231724::Y'}}
|
2012-11-15 08:31:27 +08:00
|
|
|
y->Z<int>::n; // expected-error{{'rdar8231724::Z<int>::n' is not a member of class 'rdar8231724::Y'}}
|
2015-11-12 03:34:47 +08:00
|
|
|
y->template Z<int>::n; // expected-error{{'rdar8231724::Z<int>::n' is not a member of class 'rdar8231724::Y'}}
|
|
|
|
#if __cplusplus <= 199711L // C++03 or earlier modes
|
|
|
|
// expected-warning@-2{{'template' keyword outside of a template}}
|
|
|
|
#endif
|
2010-07-29 06:27:52 +08:00
|
|
|
}
|
|
|
|
}
|
2011-02-17 10:54:17 +08:00
|
|
|
|
|
|
|
namespace PR9025 {
|
|
|
|
struct S { int x; };
|
2011-10-12 07:14:30 +08:00
|
|
|
S fun(); // expected-note{{possible target for call}}
|
|
|
|
int fun(int i); // expected-note{{possible target for call}}
|
2011-02-17 10:54:17 +08:00
|
|
|
int g() {
|
2011-10-12 07:14:30 +08:00
|
|
|
return fun.x; // expected-error{{reference to overloaded function could not be resolved; did you mean to call it with no arguments?}}
|
2011-02-17 10:54:17 +08:00
|
|
|
}
|
|
|
|
|
2011-10-12 07:14:30 +08:00
|
|
|
S fun2(); // expected-note{{possible target for call}}
|
|
|
|
S fun2(int i); // expected-note{{possible target for call}}
|
2011-02-17 10:54:17 +08:00
|
|
|
int g2() {
|
2011-10-12 07:14:30 +08:00
|
|
|
return fun2.x; // expected-error{{reference to overloaded function could not be resolved; did you mean to call it with no arguments?}}
|
2011-02-17 10:54:17 +08:00
|
|
|
}
|
2011-02-23 07:52:53 +08:00
|
|
|
|
2011-10-12 07:14:30 +08:00
|
|
|
S fun3(int i=0); // expected-note{{possible target for call}}
|
|
|
|
int fun3(int i, int j); // expected-note{{possible target for call}}
|
2011-02-23 07:52:53 +08:00
|
|
|
int g3() {
|
2011-10-12 07:14:30 +08:00
|
|
|
return fun3.x; // expected-error{{reference to overloaded function could not be resolved; did you mean to call it with no arguments?}}
|
2011-02-23 07:52:53 +08:00
|
|
|
}
|
2011-03-05 10:42:30 +08:00
|
|
|
|
2011-10-12 07:14:30 +08:00
|
|
|
template <typename T> S fun4(); // expected-note{{possible target for call}}
|
2011-03-05 10:42:30 +08:00
|
|
|
int g4() {
|
2011-10-12 07:14:30 +08:00
|
|
|
return fun4.x; // expected-error{{reference to overloaded function could not be resolved; did you mean to call it?}}
|
2011-03-05 10:42:30 +08:00
|
|
|
}
|
2011-05-05 06:10:40 +08:00
|
|
|
|
2011-10-12 07:14:30 +08:00
|
|
|
S fun5(int i); // expected-note{{possible target for call}}
|
|
|
|
S fun5(float f); // expected-note{{possible target for call}}
|
2011-05-05 06:10:40 +08:00
|
|
|
int g5() {
|
2011-10-12 07:14:30 +08:00
|
|
|
return fun5.x; // expected-error{{reference to overloaded function could not be resolved; did you mean to call it?}}
|
2011-05-05 06:10:40 +08:00
|
|
|
}
|
2011-02-17 10:54:17 +08:00
|
|
|
}
|
2012-01-13 10:20:01 +08:00
|
|
|
|
|
|
|
namespace FuncInMemberExpr {
|
|
|
|
struct Vec { int size(); };
|
|
|
|
Vec fun1();
|
|
|
|
int test1() { return fun1.size(); } // expected-error {{base of member reference is a function; perhaps you meant to call it with no arguments}}
|
|
|
|
Vec *fun2();
|
|
|
|
int test2() { return fun2->size(); } // expected-error {{base of member reference is a function; perhaps you meant to call it with no arguments}}
|
|
|
|
Vec fun3(int x = 0);
|
|
|
|
int test3() { return fun3.size(); } // expected-error {{base of member reference is a function; perhaps you meant to call it with no arguments}}
|
|
|
|
}
|
2012-04-21 09:12:48 +08:00
|
|
|
|
|
|
|
namespace DotForSemiTypo {
|
|
|
|
void f(int i) {
|
|
|
|
// If the programmer typo'd '.' for ';', make sure we point at the '.' rather
|
|
|
|
// than the "field name" (whatever the first token on the next line happens to
|
|
|
|
// be).
|
|
|
|
int j = i. // expected-error {{member reference base type 'int' is not a structure or union}}
|
|
|
|
j = 0;
|
|
|
|
}
|
|
|
|
}
|
2013-07-16 03:54:54 +08:00
|
|
|
|
|
|
|
namespace PR15045 {
|
|
|
|
class Cl0 {
|
|
|
|
public:
|
|
|
|
int a;
|
|
|
|
};
|
|
|
|
|
|
|
|
int f() {
|
|
|
|
Cl0 c;
|
2015-04-03 06:10:06 +08:00
|
|
|
return c->a; // expected-error {{member reference type 'PR15045::Cl0' is not a pointer; did you mean to use '.'?}}
|
2013-08-01 01:38:24 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
struct bar {
|
|
|
|
void func(); // expected-note {{'func' declared here}}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct foo {
|
|
|
|
bar operator->(); // expected-note 2 {{'->' applied to return value of the operator->() declared here}}
|
|
|
|
};
|
|
|
|
|
|
|
|
template <class T> void call_func(T t) {
|
2013-12-14 09:07:05 +08:00
|
|
|
t->func(); // expected-error-re 2 {{member reference type 'PR15045::bar' is not a pointer{{$}}}} \
|
2013-08-01 01:38:24 +08:00
|
|
|
// expected-note {{did you mean to use '.' instead?}}
|
|
|
|
}
|
|
|
|
|
|
|
|
void test_arrow_on_non_pointer_records() {
|
|
|
|
bar e;
|
|
|
|
foo f;
|
|
|
|
|
|
|
|
// Show that recovery has happened by also triggering typo correction
|
2015-04-03 06:10:06 +08:00
|
|
|
e->Func(); // expected-error {{member reference type 'PR15045::bar' is not a pointer; did you mean to use '.'?}} \
|
2013-08-01 01:38:24 +08:00
|
|
|
// expected-error {{no member named 'Func' in 'PR15045::bar'; did you mean 'func'?}}
|
|
|
|
|
|
|
|
// Make sure a fixit isn't given in the case that the '->' isn't actually
|
|
|
|
// the problem (the problem is with the return value of an operator->).
|
2013-12-14 09:07:05 +08:00
|
|
|
f->func(); // expected-error-re {{member reference type 'PR15045::bar' is not a pointer{{$}}}}
|
2013-08-01 01:38:24 +08:00
|
|
|
|
|
|
|
call_func(e); // expected-note {{in instantiation of function template specialization 'PR15045::call_func<PR15045::bar>' requested here}}
|
|
|
|
|
|
|
|
call_func(f); // expected-note {{in instantiation of function template specialization 'PR15045::call_func<PR15045::foo>' requested here}}
|
2013-07-16 03:54:54 +08:00
|
|
|
}
|
|
|
|
}
|
2013-08-22 03:09:44 +08:00
|
|
|
|
|
|
|
namespace pr16676 {
|
|
|
|
struct S { int i; };
|
|
|
|
struct T { S* get_s(); };
|
|
|
|
int f(S* s) {
|
|
|
|
T t;
|
|
|
|
return t.get_s // expected-error {{reference to non-static member function must be called; did you mean to call it with no arguments?}}
|
2015-04-03 06:10:06 +08:00
|
|
|
.i; // expected-error {{member reference type 'pr16676::S *' is a pointer; did you mean to use '->'}}
|
2013-08-22 03:09:44 +08:00
|
|
|
}
|
|
|
|
}
|