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
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?