blob: 981bae7c770bd47a0107ecbc72fca74797036e43 [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) {
Matt Beaumont-Gay65b34d72011-02-22 23:52:53 +000031 return b->f0->f0; // expected-error{{perhaps you meant 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) {
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}}
91 }
92}
Douglas Gregor12eb5d62010-06-29 19:27:42 +000093
94namespace PR7508 {
95 struct A {
96 struct CleanupScope {};
97 void PopCleanupBlock();
98 };
99
100 void foo(A &a) {
101 a.PopCleanupScope(); // expected-error{{no member named 'PopCleanupScope' in 'PR7508::A'}}
102 }
103}
Douglas Gregor9d4bb942010-07-28 22:27:52 +0000104
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 void f(Y *y) {
115 y->N::X1<int>; // expected-error{{'rdar8231724::N::X1' is not a member of class 'rdar8231724::Y'}}
116 }
117}
Matt Beaumont-Gay26ae5dd2011-02-17 02:54:17 +0000118
119namespace PR9025 {
120 struct S { int x; };
121 S fun();
122 int fun(int i);
123 int g() {
Matt Beaumont-Gay65b34d72011-02-22 23:52:53 +0000124 return fun.x; // expected-error{{base of member reference is an overloaded function; perhaps you meant to call it with no arguments?}}
Matt Beaumont-Gay26ae5dd2011-02-17 02:54:17 +0000125 }
126
Matt Beaumont-Gayc9366ba2011-05-04 22:10:40 +0000127 S fun2();
128 S fun2(int i);
Matt Beaumont-Gay26ae5dd2011-02-17 02:54:17 +0000129 int g2() {
Matt Beaumont-Gayc9366ba2011-05-04 22:10:40 +0000130 return fun2.x; // expected-error{{base of member reference is an overloaded function; perhaps you meant to call it with no arguments?}}
Matt Beaumont-Gay26ae5dd2011-02-17 02:54:17 +0000131 }
Matt Beaumont-Gay65b34d72011-02-22 23:52:53 +0000132
133 S fun3(int i=0);
134 int fun3(int i, int j);
135 int g3() {
136 return fun3.x; // expected-error{{base of member reference is an overloaded function; perhaps you meant to call it with no arguments?}}
137 }
Matt Beaumont-Gayfbe59942011-03-05 02:42:30 +0000138
139 template <typename T> S fun4();
140 int g4() {
141 return fun4.x; // expected-error{{base of member reference is a function; perhaps you meant to call it?}}
142 }
Matt Beaumont-Gayc9366ba2011-05-04 22:10:40 +0000143
144 S fun5(int i); // expected-note{{possibly valid overload here}}
145 S fun5(float f); // expected-note{{possibly valid overload here}}
146 int g5() {
147 return fun5.x; // expected-error{{base of member reference is an overloaded function; perhaps you meant to call it?}}
148 }
Matt Beaumont-Gay26ae5dd2011-02-17 02:54:17 +0000149}