Title
Ambiguity in new-expression with elaborated-type-specifier
Status
cd4
Section
7.6.2.8 [expr.new]
Submitter
Hubert Tong

Created on 2015-06-12.00:00:00 last changed 94 months ago

Messages

Date: 2016-02-15.00:00:00

Proposed resolution (February, 2016):

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

    • alias-declaration:
        using identifier attribute-specifier-seqopt = defining-type-id
  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:

    • decl-specifier:
        storage-class-specifier
        defining-type-specifier
        function-specifier
        friend
        typedef
        constexpr
  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:

    • type-specifier:
        trailing-type-specifier
        class-specifier
        enum-specifier
      trailing-type-specifier:
        simple-type-specifier
        elaborated-type-specifier
        typename-specifier
        cv-qualifier
      type-specifier-seq:
        type-specifier attribute-specifier-seqopt
        type-specifier type-specifier-seq
      defining-type-specifier:
        type-specifier
        class-specifier
        enum-specifier
      trailingdefining-type-specifier-seq:
        trailingdefining-type-specifier attribute-specifier-seqopt
        trailingdefining-type-specifier trailingdefining-type-specifier-seq

    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.

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

  13. 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:...
  14. Change 9.2.9 [dcl.type] paragraph 3 as follows:

  15. 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.
  16. Change the grammar in 9.3 [dcl.decl] paragraph 4 as follows:

    • trailing-return-type:
        -> trailing-type-specifier-seq abstract-declaratoropt type-id
  17. Change the grammar in 9.3.2 [dcl.name] paragraph 1 as follows:

    • type-id:
        type-specifier-seq abstract-declaratoropt
      defining-type-id:
        defining-type-specifier-seq abstract-declaratoropt
  18. Change 11.4.8.3 [class.conv.fct] paragraph 1 as follows:

  19. ...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
Date: 2016-02-15.00:00:00

[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.

History
Date User Action Args
2017-02-06 00:00:00adminsetstatus: tentatively ready -> cd4
2016-02-15 00:00:00adminsetmessages: + msg5698
2016-02-15 00:00:00adminsetstatus: drafting -> tentatively ready
2015-06-12 00:00:00admincreate