1// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
2
3
4// If P is an rvalue reference to a cv-unqualified template parameter
5// and the argument is an lvalue, the type "lvalue reference to A" is
6// used in place of A for type deduction.
7template<typename T> struct X { };
8
9template<typename T> X<T> f0(T&&);
10
11struct Y { };
12
13template<typename T> T prvalue();
14template<typename T> T&& xvalue();
15template<typename T> T& lvalue();
16
17void test_f0() {
18  X<int> xi0 = f0(prvalue<int>());
19  X<int> xi1 = f0(xvalue<int>());
20  X<int&> xi2 = f0(lvalue<int>());
21  X<Y> xy0 = f0(prvalue<Y>());
22  X<Y> xy1 = f0(xvalue<Y>());
23  X<Y&> xy2 = f0(lvalue<Y>());
24}
25
26template<typename T> X<T> f1(const T&&); // expected-note{{candidate function [with T = int] not viable: no known conversion from 'int' to 'const int &&' for 1st argument}} \
27// expected-note{{candidate function [with T = Y] not viable: no known conversion from 'Y' to 'const Y &&' for 1st argument}}
28
29void test_f1() {
30  X<int> xi0 = f1(prvalue<int>());
31  X<int> xi1 = f1(xvalue<int>());
32  f1(lvalue<int>()); // expected-error{{no matching function for call to 'f1'}}
33  X<Y> xy0 = f1(prvalue<Y>());
34  X<Y> xy1 = f1(xvalue<Y>());
35  f1(lvalue<Y>()); // expected-error{{no matching function for call to 'f1'}}
36}
37
38namespace std_example {
39  template <class T> int f(T&&);
40  template <class T> int g(const T&&); // expected-note{{candidate function [with T = int] not viable: no known conversion from 'int' to 'const int &&' for 1st argument}}
41
42  int i;
43  int n1 = f(i);
44  int n2 = f(0);
45  int n3 = g(i); // expected-error{{no matching function for call to 'g'}}
46}
47