Consider the following class S
containing a function pointer, and a constexpr
object s
of that class initialized with a lambda:
struct S
{
void (*f) ();
};
constexpr S s { []{} };
Now if I write a template X
with a non-type template parameter of type S
, and instantiate it over s
like this:
template<S> struct X {};
using x = X<s>;
clang compiles the code, but gcc complains with:
error: '<lambda()>::_FUN' is not a valid template argument of type 'void (*)()' because '<lambda()>::_FUN' is not a variable
using x = X<s>;
^
Here's the program.
The code seems fine to me, and I'm not sure what the error message is referring to. So is this code valid?
Note that both compilers accept the code if X
instead has a non-type template parameter of reference type to S
, like this:
template<S const &> struct X {};
This question was inspired by another similar question.