Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++20 template <auto> with user type leads to T/const T type mismatch in GCC 9

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?

like image 722
le migou Avatar asked Nov 29 '18 08:11

le migou


1 Answers

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.

like image 189
le migou Avatar answered Oct 31 '22 21:10

le migou