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

CWG2939 [expr.reinterpret.cast] Do not allow reinterpret_cast from prvalue to rvalue reference #617

Open
t3nsor opened this issue Oct 1, 2024 · 1 comment

Comments

@t3nsor
Copy link

t3nsor commented Oct 1, 2024

Full name of submitter: Brian Bi

Reference (section label): [expr.reinterpret.cast]

Issue description: In [expr.reinterpret.cast]/11, we have a similar issue to the one described in CWG2879: it says the operand for a cast to reference type can be a "glvalue of type T1", which combined with [basic.lval]/7 implies that a prvalue is also acceptable. No implementation accepts reinterpret_cast<double&&>(0).

Some notes in this section are also questionable:

  • Note 1 is not specific to reinterpret_cast. The padding bits in the source value are lost upon the lvalue-to-rvalue conversion.
  • Note 5 seems irrelevant.

Suggested resolution: Edit [expr.reinterpret.cast]/1:

The result of the expression reinterpret_cast(v) is the result of converting the expression v to type T. If T is an lvalue reference type or an rvalue reference to function type, the result is an lvalue; if T is an rvalue reference to object type, the result is an xvalue; otherwise, the result is a prvalue and the lvalue-to-rvalue, array-to-pointer, and function-to-pointer standard conversions are performed on the expression v. The temporary materialization conversion ([conv.rval]) is not performed on v. Conversions that can be performed explicitly using reinterpret_cast are listed below. No other conversion can be performed explicitly using reinterpret_cast.

Strike paragraph 3 (note 1).

Strike Note 5 from paragraph 6.

Convert the last sentence of [expr.reinterpret.cast]/11 into a note. Also, I suppose the footnote may need to be inlined into it? Having a footnote inside a note seems odd.

A glvalue of type T1, designating an object or function x, can be cast to the type “reference to T2” if an expression of type “pointer to T1” can be explicitly converted to the type “pointer to T2” using a reinterpret_cast. The result is that of *reinterpret_cast<T2 *>(p) where p is a pointer to x of type “pointer to T1”. [Note: No temporary is created, no copy is made, and no constructors ([class.ctor]) or conversion functions ([class.conv]) are called. end note]

@jensmaurer
Copy link
Member

CWG2939

@jensmaurer jensmaurer changed the title [expr.reinterpret.cast] Do not allow reinterpret_cast from prvalue to rvalue reference CWG2939 [expr.reinterpret.cast] Do not allow reinterpret_cast from prvalue to rvalue reference Oct 2, 2024
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

2 participants