Which compiler is right? 'template' before templated return type needed?

前端 未结 1 1181
伪装坚强ぢ
伪装坚强ぢ 2020-12-10 03:21

This snippet (taken from this question) compiles fine with g++ (as seen), so long the template before the return type is there. In contrast, VC10 does not compi

相关标签:
1条回答
  • 2020-12-10 04:03

    GCC is right. AttributeType is a dependent template-name which is followed by angle bracket <, so the keyword template is required here to remove the ambiguity1, making it clear to the compiler that what is followed is a template-name. The rule is mentioned in §14.2/4:

    When the name of a member template specialization appears after . or -> in a postfix-expression, or after nested-name-specifier in a qualified-id, and the postfix-expression or qualified-id explicitly depends on a template-parameter (14.6.2), the member template name must be prefixed by the keyword template. Otherwise the name is assumed to name a non-template.

    1 @Johannes has written a very good explanation here:

    Where and why do I have to put the "template" and "typename" keywords?

    0 讨论(0)
提交回复
热议问题