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 }
6 // { dg-options "-std=c++0x" }
7 
8 template <bool> struct sa;
9 template <> struct sa<true> {};
10 
11 template <class T, T v>
12 struct integral_constant
13 {
14 	static const T                  value = v;
15 	typedef T                       value_type;
16 	typedef integral_constant<T, v> type;
17 };
18 
19 typedef integral_constant<bool, true>  true_type;
20 typedef integral_constant<bool, false> false_type;
21 
22 template <class T> struct is_lvalue_reference     : public integral_constant<bool, false> {};
23 template <class T> struct is_lvalue_reference<T&> : public integral_constant<bool, true> {};
24 
25 template <class T> struct is_rvalue_reference      : public integral_constant<bool, false> {};
26 template <class T> struct is_rvalue_reference<T&&> : public integral_constant<bool, true> {};
27 
28 template <bool is_lvalue_ref, bool is_rvalue_ref, class T>
29 void
30 test1(T&&)
31 {
32     sa<is_lvalue_reference<T&&>::value == is_lvalue_ref> t1;
33     sa<is_rvalue_reference<T&&>::value == is_rvalue_ref> t2;
34 }
35 
36 template <bool is_lvalue_ref, bool is_rvalue_ref, class T>
37 void
38 test2(const T&&)		// { dg-error "argument" }
39 {
40     sa<is_lvalue_reference<const T&&>::value == is_lvalue_ref> t1;
41     sa<is_rvalue_reference<const T&&>::value == is_rvalue_ref> t2;
42 }
43 
44 template <bool is_lvalue_ref, bool is_rvalue_ref, class T>
45 void
46 test3(T*&&)
47 {
48     sa<is_lvalue_reference<T*&&>::value == is_lvalue_ref> t1;
49     sa<is_rvalue_reference<T*&&>::value == is_rvalue_ref> t2;
50 }
51 
52 struct A {};
53 
54 A a;
55 
56 A source() {return A();}
57 A* sourcep() {return 0;}
58 
59 int main()
60 {
61     test1<true, false>(a);
62     test1<false, true>(source());
63     test2<false, true>(a);	// { dg-error "lvalue" }
64     test2<false, true>(source());
65     test3<false, true>(&a);
66     test3<false, true>(sourcep());
67     return 0;
68 }
69