1 // I, Howard Hinnant, hereby place this code in the public domain.
3 // Test the "Augmented" template argument deduction when binding an lvalue to an rvalue reference.
5 // { dg-do compile { target c++11 } }
7 template <bool> struct sa;
8 template <> struct sa<true> {};
10 template <class T, T v>
11 struct integral_constant
13 static const T value = v;
15 typedef integral_constant<T, v> type;
18 typedef integral_constant<bool, true> true_type;
19 typedef integral_constant<bool, false> false_type;
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> {};
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> {};
27 template <bool is_lvalue_ref, bool is_rvalue_ref, class T>
31 sa<is_lvalue_reference<T&&>::value == is_lvalue_ref> t1;
32 sa<is_rvalue_reference<T&&>::value == is_rvalue_ref> t2;
35 template <bool is_lvalue_ref, bool is_rvalue_ref, class T>
37 test2(const T&&) // { dg-message "argument" }
39 sa<is_lvalue_reference<const T&&>::value == is_lvalue_ref> t1;
40 sa<is_rvalue_reference<const T&&>::value == is_rvalue_ref> t2;
43 template <bool is_lvalue_ref, bool is_rvalue_ref, class T>
47 sa<is_lvalue_reference<T*&&>::value == is_lvalue_ref> t1;
48 sa<is_rvalue_reference<T*&&>::value == is_rvalue_ref> t2;
55 A source() {return A();}
56 A* sourcep() {return 0;}
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());