Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[conv.general] Note misuses «destination type» #6559

Open
languagelawyer opened this issue Sep 10, 2023 · 0 comments
Open

[conv.general] Note misuses «destination type» #6559

languagelawyer opened this issue Sep 10, 2023 · 0 comments

Comments

@languagelawyer
Copy link
Contributor

As we know,

16 The semantics of initializers are as follows.The destination type is the type of the object or reference being initialized

Now the Note:

2 [Note 2: Expressions with a given type will be implicitly converted to other types in several contexts:

(2.1) When used as operands of operators. The operator's requirements for its operands dictate the destination type ([expr.compound]).
(2.2) When used in the condition of an if statement ([stmt.if]) or iteration statement ([stmt.iter]). The destination type is bool.
(2.3) When used in the expression of a switch statement ([stmt.switch]). The destination type is integral.
(2.4) When used as the source expression for an initialization (which includes use as an argument in a function call and use as the expression in a return statement).
The type of the entity being initialized is (generally) the destination type. See [dcl.init], [dcl.init.ref].
— end note]

The operator's requirements for its operands dictate the destination type

is wrong, because a built-in operator's operand is not an «object or reference being initialized»

(2.2) is kinda OK, because implicit conversion to bool is modeled as declaration bool t(E);

(2.3) is wrong. Class types are contextually implicitly converted (http://eel.is/c++draft/stmt.switch#2.sentence-3), and this conversion is described not relying on initialization http://eel.is/c++draft/conv.general#def:contextually_implicitly_converted

(2.4) is, obviously, OK

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant