1 // RUN: %clang_cc1 -std=c++1z -verify %s
3 // Test that we cope with failure to expand a pack.
4 template<typename ...T> struct Unexpanded : T... {
5 using T::f; // expected-error {{unexpanded}}
6 using typename T::type; // expected-error {{unexpanded}}
7 template<typename ...U> void g(U ...u) { f(u...); } // expected-error {{undeclared identifier 'f'}}
9 Unexpanded<type...> *p; // expected-error {{undeclared identifier 'type'}}
12 void test_Unexpanded() {
13 struct A { void f(); }; // expected-note {{must qualify}}
14 struct B { void f(int); }; // expected-note {{must qualify}}
15 Unexpanded<A, B>().g(0); // expected-note {{instantiation of}}
18 // Test using non-type members from pack of base classes.
19 template<typename ...T> struct A : T... { // expected-note 2{{candidate}}
20 using T::T ...; // expected-note 6{{inherited here}}
21 using T::operator() ...;
22 using T::operator T* ...;
25 void f(int n) { h(n); } // expected-error {{ambiguous}}
26 void f(int n, int m) { h(n, m); } // expected-error {{member using declaration 'h' instantiates to an empty pack}}
27 void g(int n) { (*this)(n); } // expected-error {{ambiguous}}
28 void g(int n, int m) { (*this)(n, m); } // expected-error {{does not provide a call operator}}
32 struct X { // expected-note 2{{candidate}}
34 X(int); // expected-note {{candidate}}
35 void operator()(int); // expected-note 2{{candidate}}
37 void h(int); // expected-note {{candidate}}
42 void operator()(int, int);
44 void h(int, int); // expected-note {{not viable}}
46 struct Z { // expected-note 2{{candidate}}
48 Z(int); // expected-note {{candidate}}
49 void operator()(int); // expected-note 2{{candidate}}
51 void h(int); // expected-note {{candidate}}
56 a.f(0, 0); // expected-note {{instantiation of}}
57 a.g(0, 0); // expected-note {{instantiation of}}
68 A<X, Y, Z>(0); // expected-error {{ambiguous}}
69 A<X, Y, Z> axyz(0, 0);
70 axyz.f(0); // expected-note {{instantiation of}}
72 axyz.g(0); // expected-note {{instantiation of}}
74 axyz(0); // expected-error {{ambiguous}}
78 x = a; // expected-error {{incompatible}}
81 x = a.operator X*(); // expected-error {{no member}}
82 x = axy.operator X*();
83 x = axyz.operator X*();
87 z = axyz.operator Z*();
91 // Test using pack of non-type members from single base class.
92 template<typename X, typename Y, typename ...T> struct B : X, Y {
93 using X::operator T* ...;
97 struct X { operator int*(); operator float*(); operator char*(); }; // expected-note {{candidate}}
98 struct Y { operator int*(); operator float*(); operator char*(); }; // expected-note {{candidate}}
99 B<X, Y, int, float> bif;
102 char *pc = bif; // expected-error {{ambiguous}}
105 // Test using type member from pack of base classes.
106 template<typename ...T> struct C : T... {
107 using typename T::type ...; // expected-error {{target of using declaration conflicts}}
108 void f() { type value; } // expected-error {{member using declaration 'type' instantiates to an empty pack}}
112 struct X { typedef int type; };
113 struct Y { typedef int type; }; // expected-note {{conflicting}}
114 struct Z { typedef float type; }; // expected-note {{target}}
118 c.f(); // expected-note {{instantiation of}}
123 C<X, Y, Z> cxyz; // expected-note {{instantiation of}}
128 // Test using pack of non-types at block scope.
129 template<typename ...T> int fn1() {
130 using T::e ...; // expected-error 2{{class member}} expected-note 2{{instead}}
131 // expected-error@-1 2{{produces multiple values}}
132 return e; // expected-error {{using declaration 'e' instantiates to an empty pack}}
136 struct X { static int e; };
137 struct Y { typedef int e; };
138 inline namespace P { enum E { e }; }
139 inline namespace Q { enum F { e }; }
141 fn1<>(); // expected-note {{instantiation of}}
142 fn1<X>(); // expected-note {{instantiation of}}
143 fn1<Y>(); // expected-note {{instantiation of}}
145 fn1<E, F>(); // expected-note {{instantiation of}}
146 fn1<E, X>(); // expected-note {{instantiation of}}
150 // Test using pack of types at block scope.
151 template<typename ...T> void fn2() {
152 // This cannot ever be valid: in order for T::type to be a type, T must be a
153 // class, and a class member cannot be named by a block-scope using declaration.
154 using typename T::type ...; // expected-error {{class member}}
155 type x; // expected-error {{unknown type name 'type'}}
158 // Test partial substitution into class-scope pack.
159 template<typename ...T> auto lambda1() {
161 struct A : T::template X<decltype(x)>... { // expected-note 1+{{instantiation of}}
162 using T::template X<decltype(x)>::f ...;
163 using typename T::template X<decltype(x)>::type ...;
164 void g(int n) { f(n); } // expected-error {{empty pack}} expected-error {{expected 2, have 1}} expected-error {{ambiguous}}
165 void h() { type value; } // expected-error {{empty pack}}
171 namespace test_lambda1 {
173 template<typename> struct X {
174 void f(int); // expected-note {{candidate}}
179 template<typename> struct X {
180 void f(int, int); // expected-note {{declared here}} expected-note {{not viable}}
185 template<typename> struct X {
186 void f(int); // expected-note {{candidate}}
187 void f(int, int); // expected-note {{not viable}}
193 lambda1<>() // expected-note 2{{instantiation of}}
195 // FIXME: This is poor error recovery
196 .g(0); // expected-error {{no member named 'g'}}
201 (0) // expected-note {{instantiation of}}
204 (0) // expected-note {{instantiation of}}
209 namespace p0195r2_example {
210 template<typename ...Ts>
211 struct Overloader : Ts... {
212 using Ts::operator() ...;
215 template<typename ...Ts>
216 constexpr auto make_overloader(Ts &&...ts) {
217 return Overloader<Ts...>{static_cast<Ts&&>(ts)...};
221 auto o = make_overloader(
222 [&](int &r) -> int & { return r; }, // expected-note {{candidate function}}
223 [&](float &r) -> float & { return r; } // expected-note {{candidate function}}
225 int a; float f; double d;
228 double &rd = o(d); // expected-error {{no matching function}}