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


2175. Ambiguity with attribute in conversion operator declaration

Section: 9.3.3  [dcl.ambig.res]     Status: CD4     Submitter: Daveed Vandevoorde     Date: 2015-09-17

[Adopted at the February, 2016 meeting.]

The declaration

  operator int [[noreturn]] ();

is ambiguous with respect to the binding of the attribute. It could either be parsed (as apparently intended by the user) as part of the noptr-declarator (9.3 [dcl.decl] paragraph 4) or as part of the type-specifier-seq (9.2.9 [dcl.type] paragraph 1) of the conversion-type-id (11.4.8.3 [class.conv.fct] paragraph 1) . Current implementations disambiguate this declaration in favor of the latter interpretation, issuing an error for the declaration because the noreturn attribute cannot apply to a type.

Proposed resolution (February, 2016):

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

The conversion-type-id shall not represent a function type nor an array type. The conversion-type-id in a conversion-function-id is the longest possible sequence of conversion-declarators tokens that could possibly form a conversion-type-id. [Note: This prevents ambiguities between the declarator operator * and its expression counterparts. [Example:

  &ac.operator int*i;  // syntax error:
                       // parsed as: &(ac.operator int *)i
                       // not as: &(ac.operator int)*i

The * is the pointer declarator and not the multiplication operator. —end example] This rule also prevents ambiguities for attributes. [Example:

  operator int [[noreturn]] (); // error: noreturn attribute applied to a type

end example]end note]