US 20 - forwarding references and class template argument deduction
[official-gcc.git] / gcc / testsuite / g++.dg / cpp1z / class-deduction26.C
blobea58af75de8bacaff3e9f444180b2de7b9117bc0
1 // Testcase from P0512R0 for C++17 NB comment US 20
2 // { dg-options -std=c++1z }
4 template <class,class> struct same;
5 template <class T> struct same<T,T> {};
7 template<class T> struct A {
8   template<class U>
9   A(T&&, U&&, int*); // #1: T&& is not a forwarding reference
10                      //     U&& is a forwarding reference
11   A(T&&, int*);      // #2
13 template<class T>
14 A(T&&, int*) -> A<T>; // #3: T&& is a forwarding reference
16 int i;
17 int *ip;
18 A a0{0, 0, ip}; // uses #1 to deduce A<int> and #1 to initialize
19 same<decltype(a0),A<int>> s1;
20 A a2{i, ip};    // uses #3 to deduce A<int&> and #2 to initialize
21 same<decltype(a2),A<int&>> s2;
23 A a{i, 0, ip};  // { dg-error "" } cannot deduce from #1