I'm trying to use non-type template with a custom type.
struct T {};
template <auto value> struct U {};
template <auto value>
void f (U <value>) {}
int main()
{
constexpr T t;
f (U<1>{}); // OK
f<t> (U<t>{}); // OK
f (U<t>{}); // Error
}
Template argument deduction fails, gcc trunk with -std=c++2a gets
yop.cpp:10:5: note: template argument deduction/substitution failed:
yop.cpp:19:21: note: mismatched types ‘T’ and ‘const T’
19 | f (U<t>{}); // Error
| ^
Am I missing something or is this a bug?
Ok, browsing the latest draft...
[temp.arg.nontype] says
If the type T of a template-parameter (12.1) contains a placeholder type (9.1.7.5) or a placeholder for a deduced class type (9.1.7.6), the type of the parameter is the type deduced for the variable x in the invented declaration
T x = template-argument ;
As inserting
auto x = t;
static_assert (std::is_same_v <decltype (x), T>);
in the snippet above compiles, I'm filing a bug.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With