3

Here's a small snippet of code:

template<void(*)()> struct s{};

int main() {
    s<+[]{}> t;
}

I'm trying to take the pointer to the function of the lambda. It compiles in clang but GCC rejects it:

main.cpp:5:8: error: lambda-expression in template-argument

  s<+[]{}> t;
    ^

main.cpp:5:12: error: template argument 1 is invalid

  s<+[]{}> t;
         ^

The following code compiles with both GCC and clang:

template<void(*)()> struct s{};

constexpr auto f = +[]{};
int main() {
    s<f> t;
}

Which compiler is right and why?

Guillaume Racicot
  • 39,621
  • 9
  • 77
  • 141
  • 1
    Here's a perfect dupe: https://stackoverflow.com/questions/44931130/lambda-expression-as-non-type-template-argument?noredirect=1&lq=1 – Rakete1111 May 21 '18 at 21:11

0 Answers0