Title
Ambiguity resolution for cast to function type
Status
open
Section
9.3.3 [dcl.ambig.res]
Submitter
Richard Smith

Created on 2016-02-02.00:00:00 last changed 17 months ago

Messages

Date: 2019-01-15.00:00:00

Proposed resolution (January, 2019):

Date: 2022-11-25.06:46:31

Consider:

  int x = (int()) + 5; 

This is ill-formed, because 9.3.3 [dcl.ambig.res] paragraph 2 specifies:

An ambiguity can arise from the similarity between a function-style cast and a type-id. The resolution is that any construct that could possibly be a type-id in its syntactic context shall be considered a type-id.

and thus int() is interpreted as a type-id instead of as a function-style cast, so this is an ill-formed cast to a function type.

This seems to be the wrong disambiguation for all cases where there is a choice between a C-style cast and a parenthesized expression: in all those cases, the C-style cast interpretation results in a cast to a function type, which is always ill-formed.

Further, there is implementation divergence in the handling of this example:

  struct T { int operator++(int); T operator[](int); };
  int a = (T()[3])++; // not a cast

EWG 2022-11-11

This is tracked in github issue cplusplus/papers#1376.

History
Date User Action Args
2022-11-10 15:00:26adminsetstatus: review -> open
2020-12-15 00:00:00adminsetmessages: + msg6222
2020-12-15 00:00:00adminsetstatus: drafting -> review
2018-02-27 00:00:00adminsetstatus: open -> drafting
2016-02-02 00:00:00admincreate