Clang (OS X) requires “template” keyword in a particular nested declaration, while VS forbids it

后端 未结 2 1801
-上瘾入骨i
-上瘾入骨i 2021-01-02 15:38

I am writing a cross-platform application in two compilers (Clang on Xcode v5.0.2, and Visual Studio 2012 Update 4) and I have run into a scenario in which the two compilers

相关标签:
2条回答
  • 2021-01-02 16:21

    It seems the relevant clause is 14.2 (temp.names) paragraph 4:

    When the name of a member template specialization appears after . or ->in a postfix-expression or after a nested-name-specifier in a qualified-id, and the object expression of the postfix-expression is type-dependent or the nested-name-specifier in the qualified-id refers to a dependent type, but the name is not a member of the current instantiation (14.6.2.1), the member template name must be prefixed by the keyword template.

    I think that says that template is required. Following up with DyP's comment, it seems certainly wrong to reject the keyword even if it isn't required (paragraph 5 of the same clause):

    A name prefixed by the keyword template shall be a template-id or the name shall refer to a class template. [Note: The keyword template may not be applied to non-template members of class templates. —end note] [Note: As is the case with the typename prefix, the template prefix is allowed in cases where it is not strictly necessary; i.e., when the nested-name-specifier or the expression on the left of the -> or . is not dependent on a template-parameter, or the use does not appear in the scope of a template.—end note].

    0 讨论(0)
  • 2021-01-02 16:32

    Clang is correct, Base<T> is dependent on a template parameter. This is yet another symptom of Visual C++ not implementing two-phase name lookup for templates.

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