Search code examples
c++clangvariadic-templatesnon-type-template-parameter

Cannot have separate declaration and implementation of class with custom variadic non-template parameters


Is this a bug in Clang (the default version used by Xcode 14)? The following code does not compile:

        struct TestValue
        {

        };
    
        template<TestValue... Values>
        struct TestCompiler
        {
            TestCompiler();
        };
    
        template<TestValue... Values>
        TestCompiler<Values...>::TestCompiler()
        {
            
        }

The error message is:

nested name specifier 'TestCompiler<Values...>::' for declaration does not refer into a class, class template or class template partial specialization

To reproduce this, it's necessary to have the template parameters of TestCompiler be non-template types, variadic, and custom (not built in) types. Defining the class inline compiles, it's only trying to declare and implement the class separately that fails.


Solution

  • This is a clang bug since the program is well-formed as this is the correct way of providing an out of class definition for a nontemplate ctor of a class template.

    Here is the clang bug report:

    Clang rejects valid out of class definition of a nontemplate constructor of a class template