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

2024-10-26


1990. Ambiguity due to optional decl-specifier-seq

Section: 9.1  [dcl.pre]     Status: CD4     Submitter: Hubert Tong     Date: 2014-08-27

[Moved to DR at the October, 2015 meeting.]

In an example like

  void f() {
    f();  // #1
  }

The statement at #1 is ambiguous and can be parsed as either an expression or as a declaration. The problem is the fact that the decl-specifier-seq in a simple-declaration is optional.

Proposed resolution (May, 2015):

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




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

  3. The A simple-declaration or nodeclspec-function-declaration of the form

    is divided into three parts. Attributes are described in 9.12 [dcl.attr]. decl-specifiers, the principal components of a decl-specifier-seq, are described in 9.2 [dcl.spec]. declarators, the components of an init-declarator-list, are described in 9.3 [dcl.decl]. The attribute-specifier-seq in a simple-declaration appertains to each of the entities declared by the declarators of the init-declarator-list. [Note:...

  4. Change 9.1 [dcl.pre] paragraph 11 as follows:

  5. Only in function declarations for A nodeclspec-function-declaration shall declare a constructors, destructors, and type or conversions function can the decl-specifier-seq be omitted.93 [Note: a nodeclspec-function-declaration can only be used in a template-declaration (Clause 13 [temp]), explicit-instantiation (13.9.3 [temp.explicit]), or explicit-specialization (13.9.4 [temp.expl.spec]). —end note]
  6. Change 9.3.4 [dcl.meaning] paragraph 1 as follows:

  7. A list of declarators appears after an optional ( 9.1 [dcl.pre]) decl-specifier-seq (9.2 [dcl.spec]). Each A declarator contains exactly one declarator-id; it names the identifier...
  8. Change 11.4.5 [class.ctor] paragraph 1 as follows:

  9. ...In a constructor declaration, each Each decl-specifier in the optional decl-specifier-seq of a constructor declaration (if any) shall be friend, inline, explicit, or constexpr. [Example:...
  10. Change 11.4.8.3 [class.conv.fct] paragraph 1 as follows:

  11. ...Such functions are called conversion functions. No return type can be specified. A decl-specifier in the decl-specifier-seq of a conversion function (if any) shall be neither a type-specifier nor static. If a conversion function is a member function, the The type of the conversion function (9.3.4.6 [dcl.fct]) is...
  12. Delete 11.4.8.3 [class.conv.fct] paragraph 6:

  13. Conversion functions cannot be declared static.
  14. Change 11.4.7 [class.dtor] paragraph 1 as follows:

  15. ...In a destructor declaration, each Each decl-specifier of the optional decl-specifier-seq of a destructor declaration (if any) shall be friend, inline, or virtual.

This resolution also resolves issue 2016.