Daniel Dunbar | a572887 | 2009-12-15 20:14:24 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -fsyntax-only -verify %s |
Douglas Gregor | 86f1940 | 2008-12-20 23:49:58 +0000 | [diff] [blame] | 2 | |
| 3 | class X{ |
| 4 | public: |
Douglas Gregor | b0fd483 | 2010-04-25 20:55:08 +0000 | [diff] [blame] | 5 | enum E {Enumerator}; // expected-note 2{{declared here}} |
Douglas Gregor | 86f1940 | 2008-12-20 23:49:58 +0000 | [diff] [blame] | 6 | int f(); |
| 7 | static int mem; |
| 8 | static float g(); |
| 9 | }; |
| 10 | |
| 11 | void test(X* xp, X x) { |
| 12 | int i1 = x.f(); |
| 13 | int i2 = xp->f(); |
Douglas Gregor | b0fd483 | 2010-04-25 20:55:08 +0000 | [diff] [blame] | 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 '->'}} |
Douglas Gregor | 76f7d28 | 2009-01-16 03:02:29 +0000 | [diff] [blame] | 16 | int i3 = x.Enumerator; |
| 17 | int i4 = xp->Enumerator; |
Douglas Gregor | 86f1940 | 2008-12-20 23:49:58 +0000 | [diff] [blame] | 18 | x.mem = 1; |
| 19 | xp->mem = 2; |
| 20 | float f1 = x.g(); |
| 21 | float f2 = xp->g(); |
| 22 | } |
Douglas Gregor | 214f31a | 2009-03-27 06:00:30 +0000 | [diff] [blame] | 23 | |
| 24 | struct A { |
| 25 | int f0; |
| 26 | }; |
| 27 | struct B { |
| 28 | A *f0(); |
| 29 | }; |
| 30 | int f0(B *b) { |
John McCall | 6dbba4f | 2011-10-11 23:14:30 +0000 | [diff] [blame] | 31 | return b->f0->f0; // expected-error{{did you mean to call it with no arguments}} |
Douglas Gregor | 214f31a | 2009-03-27 06:00:30 +0000 | [diff] [blame] | 32 | } |
Douglas Gregor | 8d1c9ae | 2009-10-17 22:37:54 +0000 | [diff] [blame] | 33 | |
| 34 | int i; |
| 35 | |
| 36 | namespace C { |
| 37 | int i; |
| 38 | } |
| 39 | |
| 40 | void 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 McCall | b1b4256 | 2009-12-01 22:28:41 +0000 | [diff] [blame] | 44 | |
| 45 | |
| 46 | namespace 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 Gregor | 2b147f0 | 2010-04-25 21:15:30 +0000 | [diff] [blame] | 59 | |
| 60 | namespace 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 McCall | ad00b77 | 2010-06-16 08:42:20 +0000 | [diff] [blame] | 75 | |
| 76 | namespace 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 Gregor | 12eb5d6 | 2010-06-29 19:27:42 +0000 | [diff] [blame] | 93 | |
| 94 | namespace PR7508 { |
| 95 | struct A { |
| 96 | struct CleanupScope {}; |
Kaelyn Uhrain | e4c7f90 | 2012-01-13 21:28:55 +0000 | [diff] [blame] | 97 | void PopCleanupBlock(); // expected-note{{'PopCleanupBlock' declared here}} |
Douglas Gregor | 12eb5d6 | 2010-06-29 19:27:42 +0000 | [diff] [blame] | 98 | }; |
| 99 | |
| 100 | void foo(A &a) { |
Kaelyn Uhrain | e4c7f90 | 2012-01-13 21:28:55 +0000 | [diff] [blame] | 101 | a.PopCleanupScope(); // expected-error{{no member named 'PopCleanupScope' in 'PR7508::A'; did you mean 'PopCleanupBlock'?}} |
Douglas Gregor | 12eb5d6 | 2010-06-29 19:27:42 +0000 | [diff] [blame] | 102 | } |
| 103 | } |
Douglas Gregor | 9d4bb94 | 2010-07-28 22:27:52 +0000 | [diff] [blame] | 104 | |
| 105 | namespace rdar8231724 { |
| 106 | namespace N { |
| 107 | template<typename T> struct X1; |
| 108 | int i; |
| 109 | } |
| 110 | |
| 111 | struct X { }; |
| 112 | struct Y : X { }; |
| 113 | |
Richard Smith | d653701 | 2012-11-15 00:31:27 +0000 | [diff] [blame] | 114 | template<typename T> struct Z { int n; }; |
| 115 | |
Douglas Gregor | 9d4bb94 | 2010-07-28 22:27:52 +0000 | [diff] [blame] | 116 | void f(Y *y) { |
| 117 | y->N::X1<int>; // expected-error{{'rdar8231724::N::X1' is not a member of class 'rdar8231724::Y'}} |
Richard Smith | d653701 | 2012-11-15 00:31:27 +0000 | [diff] [blame] | 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}} |
Douglas Gregor | 9d4bb94 | 2010-07-28 22:27:52 +0000 | [diff] [blame] | 121 | } |
| 122 | } |
Matt Beaumont-Gay | 26ae5dd | 2011-02-17 02:54:17 +0000 | [diff] [blame] | 123 | |
| 124 | namespace PR9025 { |
| 125 | struct S { int x; }; |
John McCall | 6dbba4f | 2011-10-11 23:14:30 +0000 | [diff] [blame] | 126 | S fun(); // expected-note{{possible target for call}} |
| 127 | int fun(int i); // expected-note{{possible target for call}} |
Matt Beaumont-Gay | 26ae5dd | 2011-02-17 02:54:17 +0000 | [diff] [blame] | 128 | int g() { |
John McCall | 6dbba4f | 2011-10-11 23:14:30 +0000 | [diff] [blame] | 129 | return fun.x; // expected-error{{reference to overloaded function could not be resolved; did you mean to call it with no arguments?}} |
Matt Beaumont-Gay | 26ae5dd | 2011-02-17 02:54:17 +0000 | [diff] [blame] | 130 | } |
| 131 | |
John McCall | 6dbba4f | 2011-10-11 23:14:30 +0000 | [diff] [blame] | 132 | S fun2(); // expected-note{{possible target for call}} |
| 133 | S fun2(int i); // expected-note{{possible target for call}} |
Matt Beaumont-Gay | 26ae5dd | 2011-02-17 02:54:17 +0000 | [diff] [blame] | 134 | int g2() { |
John McCall | 6dbba4f | 2011-10-11 23:14:30 +0000 | [diff] [blame] | 135 | return fun2.x; // expected-error{{reference to overloaded function could not be resolved; did you mean to call it with no arguments?}} |
Matt Beaumont-Gay | 26ae5dd | 2011-02-17 02:54:17 +0000 | [diff] [blame] | 136 | } |
Matt Beaumont-Gay | 65b34d7 | 2011-02-22 23:52:53 +0000 | [diff] [blame] | 137 | |
John McCall | 6dbba4f | 2011-10-11 23:14:30 +0000 | [diff] [blame] | 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}} |
Matt Beaumont-Gay | 65b34d7 | 2011-02-22 23:52:53 +0000 | [diff] [blame] | 140 | int g3() { |
John McCall | 6dbba4f | 2011-10-11 23:14:30 +0000 | [diff] [blame] | 141 | return fun3.x; // expected-error{{reference to overloaded function could not be resolved; did you mean to call it with no arguments?}} |
Matt Beaumont-Gay | 65b34d7 | 2011-02-22 23:52:53 +0000 | [diff] [blame] | 142 | } |
Matt Beaumont-Gay | fbe5994 | 2011-03-05 02:42:30 +0000 | [diff] [blame] | 143 | |
John McCall | 6dbba4f | 2011-10-11 23:14:30 +0000 | [diff] [blame] | 144 | template <typename T> S fun4(); // expected-note{{possible target for call}} |
Matt Beaumont-Gay | fbe5994 | 2011-03-05 02:42:30 +0000 | [diff] [blame] | 145 | int g4() { |
John McCall | 6dbba4f | 2011-10-11 23:14:30 +0000 | [diff] [blame] | 146 | return fun4.x; // expected-error{{reference to overloaded function could not be resolved; did you mean to call it?}} |
Matt Beaumont-Gay | fbe5994 | 2011-03-05 02:42:30 +0000 | [diff] [blame] | 147 | } |
Matt Beaumont-Gay | c9366ba | 2011-05-04 22:10:40 +0000 | [diff] [blame] | 148 | |
John McCall | 6dbba4f | 2011-10-11 23:14:30 +0000 | [diff] [blame] | 149 | S fun5(int i); // expected-note{{possible target for call}} |
| 150 | S fun5(float f); // expected-note{{possible target for call}} |
Matt Beaumont-Gay | c9366ba | 2011-05-04 22:10:40 +0000 | [diff] [blame] | 151 | int g5() { |
John McCall | 6dbba4f | 2011-10-11 23:14:30 +0000 | [diff] [blame] | 152 | return fun5.x; // expected-error{{reference to overloaded function could not be resolved; did you mean to call it?}} |
Matt Beaumont-Gay | c9366ba | 2011-05-04 22:10:40 +0000 | [diff] [blame] | 153 | } |
Matt Beaumont-Gay | 26ae5dd | 2011-02-17 02:54:17 +0000 | [diff] [blame] | 154 | } |
Eli Friedman | 059d578 | 2012-01-13 02:20:01 +0000 | [diff] [blame] | 155 | |
| 156 | namespace 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 | } |
Matt Beaumont-Gay | 7d90fe5 | 2012-04-21 01:12:48 +0000 | [diff] [blame] | 165 | |
| 166 | namespace DotForSemiTypo { |
| 167 | void 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 | } |