Movatterモバイル変換


[0]ホーム

URL:


This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21 Core Issues List revision 118c. See http://www.open-std.org/jtc1/sc22/wg21/ for the official list.

2025-10-11


1710. Missingtemplate keyword inclass-or-decltype

Section:11.7  [class.derived]    Status:C++17    Submitter:Richard Smith    Date:2013-07-03

[Adopted at the February/March, 2017 meeting.]

Aclass-or-decltype is used as abase-specifier andas amem-initializer-id that names a base class. It isspecified in 11.7 [class.derived] paragraph 1 as:

Consequently, a declaration like

  template<typename T> struct D : T::template B<int>::template C<int> {};

is ill-formed, although most implementations accept it; some actuallyrequire the use of thetemplate keyword, although the relevantwording in 13.3 [temp.names] paragraph 4 only requires it in aqualified-id, not in aclass-or-decltype. It wouldprobably be good to add a production like

to the definition ofclass-or-decltype and explicitly mentionthose contexts in 13.3 [temp.names] as not requiring use of thetemplate keyword.

Additional note (January, 2014):

This is effectively issues314 and343.

See alsoissue 1812.

Proposed resolution (February, 2014) [SUPERSEDED]:

  1. Change Clause 11 [class] paragraph 3 as follows:

  2. If a class is marked with theclass-virt-specifierfinaland it appears asabase-type-specifierclass-or-decltypein abase-clause (11.7 [class.derived]), the program isill-formed. Whenever aclass-key is followed...
  3. Change the grammar in 11.7 [class.derived] paragraph 1 asfollows:

  4. Delete paragraph 4 and change paragraph 5 of13.3 [temp.names] as follows, splitting paragraph 5 into twoparagraphs and moving the example from paragraph 4 into paragraph5:

  5. When the name of a member template specialization appears after. or-> in apostfix-expression or afteranested-name-specifier in aqualified-id, and the objectexpression of thepostfix-expression is type-dependent orthenested-name-specifier in thequalified-id refers to adependent type, but the name is not a member of the current instantiation(13.8.3.2 [temp.dep.type]), the member template name must be prefixedby the keywordtemplate. Otherwise the name is assumed to name anon-template. [Example: ... —end example]

    A name prefixed by the keywordtemplate shall beatemplate-id or the name shall refer to a class templateor alias template. [Note: The keywordtemplatemay not be applied to non-template members of classtemplates. —end note]Thenested-name-specifier(_N4567_.5.1.1 [expr.prim.general]) of

    or anested-name-specifier directly contained in such anested-name-specifier (recursively), shall not be of the form

    [Note: That is, asimple-template-id shall not beprefixed by the keywordtemplate in these cases. —endnote]

    The keywordtemplate is optional in atypename-specifier (13.8 [temp.res]),elaborated-type-specifier (9.2.9.5 [dcl.type.elab]),using-declaration (9.10 [namespace.udecl]), orclass-or-decltype (11.7 [class.derived]), and inrecursively directly-containednested-name-specifiers thereof.In these contexts, a< token is always assumed to introduceatemplate-argument-list. [Note: Thus, if the precedingname is not atemplate-name, the program is ill-formed.—end note] In other contexts, when the name of a membertemplate specialization appears after anested-name-specifier thatdenotes a dependent type, but the name is not a member of the currentinstantiation, the member template name shall be prefixed by thekeywordtemplate. Similarly, when the name of a membertemplate specialization appears after. or->in apostfix-expression (7.6.1 [expr.post]) and theobject expression of thepostfix-expression is type-dependent,but the name is not a member of the current instantiation(13.8.3.2 [temp.dep.type]), the member template name shall beprefixed by the keywordtemplate. Otherwise, the name isassumed to name a non-template. [Example:

    <From original paragraph 4>

    end example] [Note: As is the case withthetypename prefix...

This resolution also resolves issues314,343,1794, and1812.

Additional note, November, 2014:

Concerns have been expressed over the clarity and organization ofthe proposed resolution, so the issue has been moved back to "review"status to allow CWG to address these concerns.

Proposed resolution, March, 2017:

  1. Change Clause 11 [class] paragraph 3 as follows:

  2. If a class is marked with theclass-virt-specifierfinaland it appears as abase-type-specifierclass-or-decltype in abase-clause (11.7 [class.derived]), the program is ill-formed. Wheneveraclass-key is followed by aclass-head-name...
  3. Change the grammar in 11.7 [class.derived] paragraph 1 asfollows:

  4. Change 11.7 [class.derived] paragraph 2 as followx:

  5. The type denoted by abase-type-specifierAclass-or-decltype shallbedenote a class type that is not an incompletely defined class(Clause 11 [class]); this. Theclassdenoted by theclass-or-decltype ofabase-specifier is called adirect base class for theclass being defined. During the lookup for a base class name...
  6. Change 13.3 [temp.names] paragraphs 4 and 5 asfollows:

  7. When the name of a member template specialization appears after. or -> in apostfix-expression or afteranested-name-specifier in aqualified-id, and the objectexpression of thepostfix-expression is type-dependent orthenested-name-specifier in thequalified-id refers to adependent type, but the name is not a member of the currentinstantiationThe keywordtemplate is said to appearat the top level in aqualified-id if it appears outside of atemplate-argument-list ordecltype-specifier. In aqualified-id of adeclarator-id or in aqualified-id formed by aclass-head-name (Clause 11 [class]) orenum-head-name (9.8.1 [dcl.enum]),the keywordtemplate shall not appear at the top level. In aqualified-id used as the name in atypename-specifier(13.8 [temp.res]),elaborated-type-specifier(9.2.9.5 [dcl.type.elab]),using-declaration(9.10 [namespace.udecl]), orclass-or-decltype (11.7 [class.derived]), an optional keywordtemplate appearingat the top level is ignored. In these contexts, a< token isalways assumed to introduce atemplate-argument-list. In all othercontexts, when naming a template specialization of a member of an unknownspecialization (13.8.3.2 [temp.dep.type]), the member templatenamemustshall be prefixed by thekeywordtemplate.Otherwise the name is assumed to name anon-template. [Example:...

    A name prefixed by the keywordtemplate shall beatemplate-id or the name shall refer to a class templateor analias template. [Note: The keywordtemplate may notbe applied to non-template members of class templates. —endnote]...

  8. Change 13.8 [temp.res] paragraph 5 as follows:

  9. A qualified name used as the name in amem-initializer-id,abase-specifier,class-or-decltype (11.7 [class.derived]) or anelaborated-type-specifier isimplicitly assumed to name a type, without the use of thetypenamekeyword. In anested-name-specifier that immediately containsanested-name-specifier that depends on a template parameter, theidentifier orsimple-template-id is implicitly assumed to name atype, without the use of thetypename keyword. [Note: Thetypename keyword is not permitted by the syntax of theseconstructs. —end note]



[8]ページ先頭

©2009-2025 Movatter.jp