C++ Logo

std-proposals

Advanced search

[std-proposals] Defect Report: Core constant expression inverse of standard conversion sequences

From: David Ledger <davidledger_at_[hidden]>
Date: Sun, 21 Aug 2022 20:06:00 +1000
Hello W21,

The following example shows a static_cast as per [expr.static.cast#7]:

```CPP
int v = 10;
auto lambda = [v](int)
{
     return v + 32;
};
void * ptr = &lambda;
auto * reverse = static_cast<decltype(lambda) *>(ptr);
```

In a constant expression, this is invalid because of [expr.const-5.14].

However, in this case it is an inverse of a conversion sequence. Since
this causes issues when implementing a constexpr `std::function_ref` and
similar usages I believe the clause should be modified to the following:

> (5.14) a conversion from type cv void* to a pointer-to-object
type<ins>_, other than when this conversion is the inverse of any
standard conversion sequence_</ins>;

Or if it is to be more consistant with static_cast's
```[expr.static.cast#7]:

> (5.14) a conversion from type cv void* to a pointer-to-object
type<ins>_, other than when this conversion is the inverse of any
standard conversion sequence ([conv]) not containing an lvalue-to-rvalue
([conv.lval]), array-to-pointer ([conv.array]), function-to-pointer
([conv.func]), null pointer ([conv.ptr]), null member pointer
([conv.mem]), boolean ([conv.bool]), or function pointer ([conv.fctptr])
conversion_</ins>;

PS. I acciddently sent this to the wrong contact. I believe it was
previously sent to wg21bot_at_gmx.net. Which could be an issue, apologies.

Regards,

     David Ledger

Received on 2022-08-21 10:06:05