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

2024-12-19


2141. Ambiguity in new-expression with elaborated-type-specifier

Section: 7.6.2.8  [expr.new]     Status: CD4     Submitter: Hubert Tong     Date: 2015-06-12

[Adopted at the February, 2016 meeting.]

Consider the following example:

  struct A { };

  void foo() {
    new struct A { };
  }

This could be either an elaborated-type-specifier followed by a braced-init-list or a class-specifier. There does not appear to be a disambiguation rule for this case.

One possibility for addressing this could be to use trailing-type-specifier-seq instead of type-specifier-seq in new-type-id. That could also be a purely syntactic alternative to the resolution of issue 686: change all uses of type-specifier-seq to trailing-type-specifier-seq and provide a new grammar production for use in alias-declaration.

Proposed resolution (February, 2016):

  1. Change the grammar in 9.1 [dcl.pre] paragraph 1 as follows:

  2. Change 9.1 [dcl.pre] paragraph 8 as follows:

  3. Each init-declarator in the init-declarator-list contains exactly one declarator-id, which is the name declared by that init-declarator and hence one of the names declared by the declaration. The defining-type-specifiers (9.2.9 [dcl.type]) in the decl-specifier-seq and the recursive declarator structure of the init-declarator describe a type (9.3.4 [dcl.meaning]), which is then associated with the name being declared by the init-declarator.
  4. Change the grammar in 9.2 [dcl.spec] paragraph 1 as follows:

  5. Change 9.2 [dcl.spec] paragraph 3 as follows:

  6. If a type-name is encountered while parsing a decl-specifier-seq, it is interpreted as part of the decl-specifier-seq if and only if there is no previous defining-type-specifier other than a cv-qualifier in the decl-specifier-seq. The sequence...
  7. Change 9.2.4 [dcl.typedef] paragraph 1 as follows:

  8. Declarations containing the decl-specifier typedef declare identifiers that can be used later for naming fundamental (6.8.2 [basic.fundamental]) or compound (6.8.4 [basic.compound]) types. The typedef specifier shall not be combined in a decl-specifier-seq with any other kind of specifier except a defining-type-specifier, and it shall not be used in the decl-specifier-seq of a parameter-declaration (9.3.4.6 [dcl.fct]) nor in the decl-specifier-seq of a function-definition (9.5 [dcl.fct.def]).
  9. Change 9.2.4 [dcl.typedef] paragraph 2 as follows:

  10. A typedef-name can also be introduced by an alias-declaration. The identifier following the using keyword becomes a typedef-name and the optional attribute-specifier-seq following the identifier appertains to that typedef-name. It The defining-type-specifier-seq of the defining-type-id may define a class or enumeration only if the alias-declaration is not the declaration of a template-declaration. Such a typedef-name has the same semantics as if it were introduced by the typedef specifier. In particular, it does not define a new type. [Example:
  11. Change 9.2.9 [dcl.type] paragraph 1 as follows:

  12. The optional attribute-specifier-seq in a type-specifier-seq or a trailingdefining-type-specifier-seq appertains to the type denoted by the preceding type-specifiers or defining-type-specifiers (9.3.4 [dcl.meaning]). The attribute-specifier-seq affects the type only for the declaration it appears in, not other declarations involving the same type.

  13. Change 9.2.9.3 [dcl.type.simple] paragraph 2 as follows:

  14. As a general rule, at most one defining-type-specifier is allowed in the complete decl-specifier-seq of a declaration or in a type-specifier-seq or trailingdefining-type-specifier-seq. The only exceptions to this rule are the following:...
  15. Change 9.2.9 [dcl.type] paragraph 3 as follows:

  16. Except in a declaration of a constructor, destructor, or conversion function, at least one defining-type-specifier that is not a cv-qualifier shall appear in a complete type-specifier-seq or a complete decl-specifier-seq.95 A type-specifier-seq shall not define a class or enumeration unless it appears in the type-id of an alias-declaration (9.2.4 [dcl.typedef]) that is not the declaration of a template-declaration.
  17. Change the grammar in 9.3 [dcl.decl] paragraph 4 as follows:

  18. Change the grammar in 9.3.2 [dcl.name] paragraph 1 as follows:

  19. Change 11.4.8.3 [class.conv.fct] paragraph 1 as follows:

  20. ...A decl-specifier in the decl-specifier-seq of a conversion function (if any) shall be neither a defining-type-specifier nor static. Type of the conversion function