This ought to work: struct S { int a; int b; }; template<S s = {1, 2}> struct X {}; X x; // ok, X<{1, 2}> but we reject it with: z.C:7:3: error: class template argument deduction failed: 7 | X x; // ok, X<{1, 2}> | ^ z.C:7:3: error: no matching function for call to ‘X()’ z.C:6:31: note: candidate: ‘template<S s> X()-> X<s>’ 6 | template<S s = {1, 2}> struct X {}; | ^ z.C:6:31: note: template argument deduction/substitution failed: z.C:6:21: error: could not convert ‘{1, 2}’ from ‘<brace-enclosed initializer list>’ to ‘S’ 6 | template<S s = {1, 2}> struct X {}; | ^
But actually this works so I'm not sure if there's anything to be done except adding the test. #define SA(X) static_assert((X),#X) struct S { int a; int b; constexpr S(int, int) : a(1), b(2) { } }; template<S s = {1, 2}> struct X { static constexpr int i = s.a; static constexpr int j = s.b; }; X x; // ok, X<{1, 2}> SA (x.i == 1); SA (x.j == 2);
Err, this one: #define SA(X) static_assert((X),#X) struct S { int a; int b; constexpr S(int a_, int b_) : a{a_}, b{b_} { } }; template<S s = {1, 2}> struct X { static constexpr int i = s.a; static constexpr int j = s.b; }; X x; // ok, X<{1, 2}> X<{3, 4}> x2; SA (x.i == 1); SA (x.j == 2); SA (x2.i == 3); SA (x2.j == 4);
Author: mpolacek Date: Tue Jan 8 23:54:47 2019 New Revision: 267744 URL: https://gcc.gnu.org/viewcvs?rev=267744&root=gcc&view=rev Log: PR c++/88744 * g++.dg/cpp2a/nontype-class12.C: New test. Added: trunk/gcc/testsuite/g++.dg/cpp2a/nontype-class12.C Modified: trunk/gcc/testsuite/ChangeLog
Added.