Out-of-class definition of a static member of a variadic template class with non-type parameter pack dependent on a containing class's parameter pack
Asked Answered
K

0

6

For the following code:

template<class... Parameter> struct Outer
{
    template<Parameter... Value> struct Inner
    {
        static bool Member;
    };
};

template<class... Parameter>
template<Parameter... Value>
bool Outer<Parameter...>::Inner<Value...>::Member = true;

int main()
{
    Outer<int>::Inner<0>::Member = false;
    return 0;
}

GCC 7.3.0 reports:

error: expansion pattern 'Value' contains no argument packs
 bool Outer<Parameter...>::Inner<Value...>::Member = true;

and Visual Studio 16.7.2, simlarly, about the same Value parameter pack:

error C3546: '...': there are no parameter packs available to expand

Both compilers succeed, if in the same code Parameter is not a parameter pack, or Value is not dependent on Parameter.

Why are those errors occurring? Does this case require some special syntax?

I know that since c++17 it can be solved by defining the member inside the class with the inline keyword. However I would prefer my code to be compatible with c++11, if it's possible.

Kilkenny answered 31/8, 2020 at 14:25 Comment(5)
Suggestion: Outer<Parameter...>::template Inner<Value...>?Turban
@Turban No, not working either.Kilkenny
that's crazy, I tried some forms and I got "fatal error C1001: Internal compiler error.", honestly speaking I never seen this before.Seek
I passed the compile using Clang 10.0.0, I think this is somehow related to compiler implementation, maybe another undefined behavior trap?Seek
@ravenisadesk Yeah, I think UB is possible. clang trunk doesn't accept this.Longitudinal

© 2022 - 2024 — McMap. All rights reserved.