1 // I, Howard Hinnant, hereby place this code in the public domain.
2 
3 // Test the "Augmented" template argument deduction when binding an lvalue to an rvalue reference.
4 
5 // { dg-do compile { target c++11 } }
6 
7 template <bool> struct sa;
8 template <> struct sa<true> {};
9 
10 template <class T, T v>
11 struct integral_constant
12 {
13 	static const T                  value = v;
14 	typedef T                       value_type;
15 	typedef integral_constant<T, v> type;
16 };
17 
18 typedef integral_constant<bool, true>  true_type;
19 typedef integral_constant<bool, false> false_type;
20 
21 template <class T> struct is_lvalue_reference     : public integral_constant<bool, false> {};
22 template <class T> struct is_lvalue_reference<T&> : public integral_constant<bool, true> {};
23 
24 template <class T> struct is_rvalue_reference      : public integral_constant<bool, false> {};
25 template <class T> struct is_rvalue_reference<T&&> : public integral_constant<bool, true> {};
26 
27 template <bool is_lvalue_ref, bool is_rvalue_ref, class T>
28 void
29 test1(T&&)
30 {
31     sa<is_lvalue_reference<T&&>::value == is_lvalue_ref> t1;
32     sa<is_rvalue_reference<T&&>::value == is_rvalue_ref> t2;
33 }
34 
35 template <bool is_lvalue_ref, bool is_rvalue_ref, class T>
36 void
37 test2(const T&&)		// { dg-message "argument" }
38 {
39     sa<is_lvalue_reference<const T&&>::value == is_lvalue_ref> t1;
40     sa<is_rvalue_reference<const T&&>::value == is_rvalue_ref> t2;
41 }
42 
43 template <bool is_lvalue_ref, bool is_rvalue_ref, class T>
44 void
45 test3(T*&&)
46 {
47     sa<is_lvalue_reference<T*&&>::value == is_lvalue_ref> t1;
48     sa<is_rvalue_reference<T*&&>::value == is_rvalue_ref> t2;
49 }
50 
51 struct A {};
52 
53 A a;
54 
55 A source() {return A();}
56 A* sourcep() {return 0;}
57 
58 int main()
59 {
60     test1<true, false>(a);
61     test1<false, true>(source());
62     test2<false, true>(a);	// { dg-error "lvalue" }
63     test2<false, true>(source());
64     test3<false, true>(&a);
65     test3<false, true>(sourcep());
66     return 0;
67 }
68