The simplest snippet I managed to get to reproduce the problem is as follows:
#include <variant>
template <auto V>
using ic = std::integral_constant<decltype(V), V>;
enum { shake };
int milk(ic<shake>);
template <class...>
struct context {
template <auto V>
decltype(milk(ic<V>{})) get() {
return std::get<decltype(milk(ic<V>{}))>(value);
}
std::variant<int> value;
};
int main(){
context<int> c;
c.get<shake>();
}
There is something fishy going on here in [clang] as it suggests that:
prog.cc:13:42: error: a non-type template parameter cannot have type 'auto'
return std::get<decltype(milk(ic<V>{}))>(value);
^
prog.cc:3:16: note: template parameter is declared here
template <auto V>
^
1 error generated.
When we change the ic
to an aliased type or use the untemplated version of context
everything works as expected. So is it really clang's bug or am I missing something obvious here?
PS. In [gcc] everything works as expected...
Which parameter is legal for non-type template? Explanation: The following are legal for non-type template parameters:integral or enumeration type, Pointer to object or pointer to function, Reference to object or reference to function, Pointer to member.
Non-type template arguments are normally used to initialize a class or to specify the sizes of class members. For non-type integral arguments, the instance argument matches the corresponding template parameter as long as the instance argument has a value and sign appropriate to the parameter type.
A template argument for a template template parameter is the name of a class template. When the compiler tries to find a template to match the template template argument, it only considers primary class templates. (A primary template is the template that is being specialized.)
Template parameters may have default arguments. The set of default template arguments accumulates over all declarations of a given template.
Clang bug as commented by xskxzr
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