1 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
2 // RUN: %clang_cc1 -std=c++1z -fsyntax-only -verify %s
4 // A forwarding reference is an rvalue reference to a cv-unqualified template
5 // parameter that does not represent a template parameter of a class template.
6 #if __cplusplus > 201402L
7 namespace ClassTemplateParamNotForwardingRef
{
8 // This is not a forwarding reference.
9 template<typename T
> struct A
{ // expected-note {{candidate}} expected-note {{implicit deduction guide}}
10 A(T
&&); // expected-note {{expects an rvalue}} expected-note {{implicit deduction guide}}
13 A a
= n
; // expected-error {{no viable constructor or deduction guide}}
18 // This is a forwarding reference.
19 template<typename T
> A(T
&&) -> A
<T
>;
26 template<typename T
= void> struct B
{
27 // This is a forwarding reference.
28 template<typename U
> B(U
&&);
35 // If P is a forwarding reference and the argument is an lvalue, the type
36 // "lvalue reference to A" is used in place of A for type deduction.
37 template<typename T
> struct X
{ };
39 template<typename T
> X
<T
> f0(T
&&);
43 template<typename T
> T
prvalue();
44 template<typename T
> T
&& xvalue();
45 template<typename T
> T
& lvalue();
48 X
<int> xi0
= f0(prvalue
<int>());
49 X
<int> xi1
= f0(xvalue
<int>());
50 X
<int&> xi2
= f0(lvalue
<int>());
51 X
<Y
> xy0
= f0(prvalue
<Y
>());
52 X
<Y
> xy1
= f0(xvalue
<Y
>());
53 X
<Y
&> xy2
= f0(lvalue
<Y
>());
56 template<typename T
> X
<T
> f1(const T
&&); // expected-note{{candidate function [with T = int] not viable: expects an rvalue for 1st argument}} \
57 // expected-note{{candidate function [with T = Y] not viable: expects an rvalue for 1st argument}}
60 X
<int> xi0
= f1(prvalue
<int>());
61 X
<int> xi1
= f1(xvalue
<int>());
62 f1(lvalue
<int>()); // expected-error{{no matching function for call to 'f1'}}
63 X
<Y
> xy0
= f1(prvalue
<Y
>());
64 X
<Y
> xy1
= f1(xvalue
<Y
>());
65 f1(lvalue
<Y
>()); // expected-error{{no matching function for call to 'f1'}}
68 namespace std_example
{
69 template <class T
> int f(T
&&);
70 template <class T
> int g(const T
&&); // expected-note{{candidate function [with T = int] not viable: expects an rvalue for 1st argument}}
75 int n3
= g(i
); // expected-error{{no matching function for call to 'g'}}
77 #if __cplusplus > 201402L
78 template<class T
> struct A
{ // expected-note {{candidate}} expected-note {{implicit deduction guide}}
80 A(T
&&, U
&&, int *); // expected-note {{[with T = int, U = int] not viable: expects an rvalue}} \
81 // expected-note {{implicit deduction guide declared as 'template <class T, class U> A(T &&, U &&, int *) -> A<T>'}}
82 A(T
&&, int *); // expected-note {{requires 2}} \
83 // expected-note {{implicit deduction guide declared as 'template <class T> A(T &&, int *) -> A<T>'}}
85 template<class T
> A(T
&&, int *) -> A
<T
>; // expected-note {{requires 2}}
88 A a
{i
, 0, ip
}; // expected-error {{no viable constructor or deduction guide}}