Reid Kleckner | 744e3e7 | 2015-10-20 21:04:13 +0000 | [diff] [blame] | 1 | // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s |
| 2 | // RUN: %clang_cc1 -std=c++98 -fsyntax-only -verify %s |
Anders Carlsson | 4bb87ce | 2009-08-29 19:37:28 +0000 | [diff] [blame] | 3 | |
John McCall | 8005382 | 2009-12-03 00:58:24 +0000 | [diff] [blame] | 4 | namespace test0 { |
| 5 | namespace N { } |
Douglas Gregor | e0b2866 | 2009-11-17 06:07:40 +0000 | [diff] [blame] | 6 | |
John McCall | 8005382 | 2009-12-03 00:58:24 +0000 | [diff] [blame] | 7 | template<typename T> |
| 8 | struct A { |
| 9 | void f(); |
| 10 | }; |
Anders Carlsson | 4bb87ce | 2009-08-29 19:37:28 +0000 | [diff] [blame] | 11 | |
John McCall | 8005382 | 2009-12-03 00:58:24 +0000 | [diff] [blame] | 12 | template<typename T> |
| 13 | struct B : A<T> { |
| 14 | using A<T>::f; |
| 15 | |
| 16 | void g() { |
| 17 | using namespace N; |
| 18 | f(); |
| 19 | } |
| 20 | }; |
| 21 | |
| 22 | template struct B<int>; |
| 23 | } |
| 24 | |
| 25 | namespace test1 { |
| 26 | template <class Derived> struct Visitor1 { |
| 27 | void Visit(struct Object1*); |
| 28 | }; |
| 29 | template <class Derived> struct Visitor2 { |
| 30 | void Visit(struct Object2*); // expected-note {{candidate function}} |
| 31 | }; |
| 32 | |
| 33 | template <class Derived> struct JoinVisitor |
| 34 | : Visitor1<Derived>, Visitor2<Derived> { |
| 35 | typedef Visitor1<Derived> Base1; |
| 36 | typedef Visitor2<Derived> Base2; |
| 37 | |
| 38 | void Visit(struct Object1*); // expected-note {{candidate function}} |
| 39 | using Base2::Visit; |
| 40 | }; |
| 41 | |
John McCall | 3155f57 | 2010-04-09 19:03:51 +0000 | [diff] [blame] | 42 | class Knot : public JoinVisitor<Knot> { |
John McCall | 8005382 | 2009-12-03 00:58:24 +0000 | [diff] [blame] | 43 | }; |
| 44 | |
| 45 | void test() { |
| 46 | Knot().Visit((struct Object1*) 0); |
| 47 | Knot().Visit((struct Object2*) 0); |
| 48 | Knot().Visit((struct Object3*) 0); // expected-error {{no matching member function for call}} |
Anders Carlsson | 4bb87ce | 2009-08-29 19:37:28 +0000 | [diff] [blame] | 49 | } |
John McCall | 8005382 | 2009-12-03 00:58:24 +0000 | [diff] [blame] | 50 | } |
John McCall | a1d8550 | 2009-12-22 22:26:37 +0000 | [diff] [blame] | 51 | |
| 52 | // PR5847 |
| 53 | namespace test2 { |
| 54 | namespace ns { |
| 55 | void foo(); |
| 56 | } |
| 57 | |
| 58 | template <class T> void bar(T* ptr) { |
| 59 | using ns::foo; |
| 60 | foo(); |
| 61 | } |
| 62 | |
| 63 | template void bar(char *); |
| 64 | } |
Douglas Gregor | ac2e430 | 2010-09-29 17:58:28 +0000 | [diff] [blame] | 65 | |
| 66 | namespace test3 { |
| 67 | template <typename T> struct t { |
| 68 | struct s1 { |
| 69 | T f1() const; |
| 70 | }; |
| 71 | struct s2 : s1 { |
| 72 | using s1::f1; |
| 73 | T f1() const; |
| 74 | }; |
| 75 | }; |
| 76 | |
| 77 | void f2() |
| 78 | { |
| 79 | t<int>::s2 a; |
| 80 | t<int>::s2 const & b = a; |
| 81 | b.f1(); |
| 82 | } |
| 83 | } |
Eli Friedman | 0eaf10b | 2013-08-20 00:39:40 +0000 | [diff] [blame] | 84 | |
| 85 | namespace PR16936 { |
| 86 | // Make sure both using decls are properly considered for |
| 87 | // overload resolution. |
| 88 | template<class> struct A { |
| 89 | void access(int); |
| 90 | }; |
| 91 | template<class> struct B { |
| 92 | void access(); |
| 93 | }; |
| 94 | template<class CELL> struct X : public A<CELL>, public B<CELL> { |
| 95 | using A<CELL>::access; |
| 96 | using B<CELL>::access; |
| 97 | |
| 98 | void f() { |
| 99 | access(0); |
| 100 | } |
| 101 | }; |
| 102 | |
| 103 | void f() { |
| 104 | X<int> x; |
| 105 | x.f(); |
| 106 | } |
| 107 | } |
Reid Kleckner | 744e3e7 | 2015-10-20 21:04:13 +0000 | [diff] [blame] | 108 | |
| 109 | namespace pr21923 { |
| 110 | template <typename> struct Base { |
| 111 | int field; |
| 112 | void method(); |
| 113 | }; |
| 114 | template <typename Scalar> struct Derived : Base<Scalar> { |
| 115 | using Base<Scalar>::field; |
| 116 | using Base<Scalar>::method; |
| 117 | static void m_fn1() { |
| 118 | // expected-error@+1 {{invalid use of member 'field' in static member function}} |
| 119 | (void)field; |
| 120 | // expected-error@+1 {{invalid use of member 'field' in static member function}} |
| 121 | (void)&field; |
| 122 | // expected-error@+1 {{call to non-static member function without an object argument}} |
| 123 | (void)method; |
| 124 | // expected-error@+1 {{call to non-static member function without an object argument}} |
| 125 | (void)&method; |
| 126 | // expected-error@+1 {{call to non-static member function without an object argument}} |
| 127 | method(); |
| 128 | (void)&Base<Scalar>::field; |
| 129 | (void)&Base<Scalar>::method; |
| 130 | } |
| 131 | #if __cplusplus >= 201103L |
| 132 | // These usages are OK in C++11 due to the unevaluated context. |
| 133 | enum { TheSize = sizeof(field) }; |
| 134 | typedef decltype(field) U; |
| 135 | #else |
| 136 | // expected-error@+1 {{invalid use of non-static data member 'field'}} |
| 137 | enum { TheSize = sizeof(field) }; |
| 138 | #endif |
| 139 | }; |
| 140 | |
| 141 | #if __cplusplus < 201103L |
| 142 | // C++98 has an extra note for TheSize. |
| 143 | // expected-note@+2 {{requested here}} |
| 144 | #endif |
| 145 | template class Derived<int>; // expected-note {{requested here}} |
| 146 | |
| 147 | // This is interesting because we form an UnresolvedLookupExpr in the static |
| 148 | // function template and an UnresolvedMemberExpr in the instance function |
| 149 | // template. As a result, we get slightly different behavior. |
| 150 | struct UnresolvedTemplateNames { |
| 151 | template <typename> void maybe_static(); |
| 152 | #if __cplusplus < 201103L |
| 153 | // expected-warning@+2 {{default template arguments for a function template are a C++11 extension}} |
| 154 | #endif |
| 155 | template <typename T, typename T::type = 0> static void maybe_static(); |
| 156 | |
| 157 | template <typename T> |
| 158 | void instance_method() { (void)maybe_static<T>(); } |
| 159 | template <typename T> |
| 160 | static void static_method() { |
| 161 | // expected-error@+1 {{call to non-static member function without an object argument}} |
| 162 | (void)maybe_static<T>(); |
| 163 | } |
| 164 | }; |
| 165 | void force_instantiation(UnresolvedTemplateNames x) { |
| 166 | x.instance_method<int>(); |
| 167 | UnresolvedTemplateNames::static_method<int>(); // expected-note {{requested here}} |
| 168 | } |
| 169 | } // pr21923 |