C++ Logo


Advanced search

Re: What's going on with non-transient constexpr allocations?

From: Brian Bi <bbi5291_at_[hidden]>
Date: Fri, 14 Jun 2019 12:23:32 -0500
On Thu, Jun 13, 2019 at 8:52 PM Tam S. B. via Std-Discussion <
std-discussion_at_[hidden]> wrote:

> I don't know previous discussion, but I guess this is a problematic case:
> template<int> struct X;
> constexpr std::vector<std::unique_ptr<int>> V = ...;
> auto f() -> X<*V[0]>;
> *V[0] = 42;
> auto f() -> X<*V[0]>;
> Here two declarations of `f()` need to have the same type, but it won't be
> possible if `*V[0]` doesn't have a constant value.
> --
> Std-Discussion mailing list
> Std-Discussion_at_[hidden]
> http://lists.isocpp.org/mailman/listinfo.cgi/std-discussion

I don't think that would pose a problem under the current wording of P0784,
since *V[0] would not be a constant expression, and in general any
lvalue-to-rvalue conversion performed on a non-transient constexpr
allocation would be disallowed in a constant expression.

Though, thinking about this raises more questions. I suppose the challenge
is to find a way to allow something like:

constexpr std::vector<int> W = ...;
constexpr int x = W[0];

while disallowing your example.

It would be really great if someone who knows what exactly is going on
would chime in.
*Brian Bi*

Received on 2019-06-14 12:25:34