CWG Issue 1990 (original) (raw)

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

2025-04-13


1990. Ambiguity due to optional decl-specifier-seq

Section: 9.1 [dcl.pre]Status: CD4Submitter: Hubert TongDate: 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: declaration: block-declaration
    nodeclspec-function-declaration
    function_definition ...

nodeclspec-function-declaration: attribute-specifier-seqopt declarator ;

alias-declaration: using identifier attribute-specifier-seqopt = type-id ;

simple-declaration: decl-specifier-seqopt init-declarator-list ;
attribute-specifier-seq decl-specifier-seqopt init-declarator-list ; ... 2. Change 9.1 [dcl.pre] paragraph 2 as follows:

The A simple-declaration or_nodeclspec-function-declaration_ of the form

attribute-specifier-seqopt decl-specifier-seqopt init-declarator-listopt ;

is divided into three parts. Attributes are described in 9.13 [dcl.attr]. _decl-specifier_s, 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:...

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

Only in function declarations for A_nodeclspec-function-declaration_ shall declare aconstructors, 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_]

  1. Change 9.3.4 [dcl.meaning] paragraph 1 as follows:

A list of declarators appears after an optional ( 9.1 [dcl.pre]) decl-specifier-seq(9.2 [dcl.spec]). Each Adeclarator contains exactly one declarator-id; it names the identifier...

  1. Change 11.4.5 [class.ctor] paragraph 1 as follows:

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

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

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

  1. Delete 11.4.8.3 [class.conv.fct] paragraph 6:

Conversion functions cannot be declared static.

  1. Change 11.4.7 [class.dtor] paragraph 1 as follows:

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

This resolution also resolves issue 2016.