Skip to content

[expr.type.conv]/2: Priority of first "if", and binding of "otherwise" #1591

@hubert-reinterpretcast

Description

@hubert-reinterpretcast

In subclause 8.2.3 [expr.type.conv] paragraph 2 of the 2017 DIS, the structure of:

If the initializer is a parenthesized single expression, the type conversion expression is equivalent (in definedness, and if defined in meaning) to the corresponding cast expression ([expr.cast]).
If the type is cv void and the initializer is (), [ ... ].
Otherwise, [an] object is direct-initialized (11.6) with the initializer.

Presents a interpretation where the first sentence is elaborated upon by the latter two as opposed to covering disjoint cases.

Given:

int *f(void *p) {
  typedef int *IntPtr;
  return IntPtr(p);
}

The C-style cast interpretation is valid; however, the direct-initialization is not.
Thus the first sentence conflicts with the latter two under said interpretation.

Furthermore, the parenthetical in the first sentence is meant to be parsed as:

equivalent (in definedness; and if defined, in meaning) to the corresponding cast expression

However, it may be taken as:

equivalent in definedness, should the corresponding cast expression be defined

Suggestion:
Move the latter two sentences under an "Otherwise" bound to the first, with appropriate indentation.
Indent the "then" part of the first as well.

Suggestion:
Improve punctuation within the parenthetical in the first sentence.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions