C++ Logo

std-proposals

Advanced search

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

From: Brian Bi <bbi5291_at_[hidden]>
Date: Sun, 21 Aug 2022 21:00:02 -0400
On Sun, Aug 21, 2022 at 6:06 AM David Ledger via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> 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>;
>

I seem to recall some discussion on the predecessor of this mailing list
about implementation difficulty of allowing casts from void* in constant
expressions, but I keep failing to find the thread.

I'm not sure if your proposed restriction makes it any easier to implement.
I wish whoever originally posted the post that I'm thinking about would
post a reply :)

> 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
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>


-- 
*Brian Bi*

Received on 2022-08-22 01:00:15