clang++ not accepting use of template template parameter when using CRTP

前端 未结 1 574
北恋
北恋 2020-12-06 05:08

I\'m getting compilation errors when trying to call the base class constructor in derived initialization list when using a template template parameter with CRTP.

相关标签:
1条回答
  • 2020-12-06 05:39

    Your code is legal.

    From the C++11 Standard, section 14.6.1:

    Like normal (non-template) classes, class templates have an injected-class-name (Clause 9). The injected-class-name can be used as a template-name or a type-name. When it is used with a template-argument-list, as a template-argument for a template template-parameter, or as the final identifier in the elaborated-type- specifier of a friend class template declaration, it refers to the class template itself.

    Looks like your version of clang is still implementing the old rule. Based on your additional comments, it might be doing so only in the ctor-initializer-list.


    User David Rodríguez - dribeas provided a workaround for compilers that haven't fully implemented the C++11 injected-class-name rule. Use any name of the class that isn't unqualified, for example:

    derived()
        : base< ::derived, T >()
    //          ^^ qualified with global namespace
    { }
    

    Some compilers may require this in the inheritance list also:

    template <class T>
    struct derived : public base< ::derived, T >
    //                            ^^
    
    0 讨论(0)
提交回复
热议问题