0

I'm trying to define a lambda template variable (static constexpr) inside of a template class. The template variable takes in a NTTP, which I want to be a size_t.

I'm able to do so in certain situations, like if the NTTP is auto instead of size_t. I'm also able to do so if the class itself isn't a template class. But if I try to use a NTTP (size_t) for the lambda within a template class, I get:

internal compiler error: unexpected expression ‘<enumerator>’ of kind template_parm_index

Live example: https://onlinegdb.com/Sk3wC7nyP

Code below:

template<size_t>
struct Foo{
    // internal compiler error: unexpected expression ‘<enumerator>’ of kind template_parm_index
    template<size_t>
    static constexpr auto foo = [](){};
};

template<size_t>
struct Bar{
    // OK
    template<auto>
    static constexpr auto foo = [](){};
};

struct Baz{
    // OK
    template<size_t>
    static constexpr auto bar = [](){};
};
Sean
  • 393
  • 2
  • 11
  • Looks like a compiler bug in `gcc 7`, the code compiles fine with `gcc 8` and newer. [godbolt example](https://godbolt.org/z/4q43sb) – IlCapitano Jul 15 '20 at 07:31
  • @IlCapitano: Looks like? No, an "internal compiler error" is always a bug :-) Simply use a up to date compiler. Current release is 10.1. So please forget the fully outdated 7 series. – Klaus Jul 15 '20 at 07:35

0 Answers0