On Mon, 22 Aug 2022, 02:00 Brian Bi via Std-Proposals, <std-proposals@lists.isocpp.org> wrote:

On Sun, Aug 21, 2022 at 6:06 AM David Ledger via Std-Proposals <std-proposals@lists.isocpp.org> wrote:
Hello W21,

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

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 :)

Yes, you're not going to get compile time type erasure via function pointers in as a defect report. Even virtual functions would be a full on proposal.