C++ Logo


Advanced search

Re: is_complete type trait?

From: Ville Voutilainen <ville.voutilainen_at_[hidden]>
Date: Fri, 12 Nov 2021 11:48:25 +0200
On Fri, 12 Nov 2021 at 11:40, Bjorn Reese via Std-Proposals
<std-proposals_at_[hidden]> wrote:
> On 11/12/21 10:31 AM, Bjorn Reese via Std-Proposals wrote:
> > On 11/12/21 2:05 AM, connor horman via Std-Proposals wrote:
> >> is_complete is a pure footgun. You can write it in pure C++ today, but
> >> there are many questions about how it behaves, that can really only be
> >> answered with "UB" or IFNDR. For example:
> >
> > Yes, this is why I asked if there have been any proposals, as they would
> > have to address such topics.
> Furthermore, many existing type traits requires complete types, so the
> standard C++ library implementations must check for completeness today.

Those traits don't need to tolerate a false answer to a completeness
query. They're not using
a trait for that question, because it cannot be implemented with a
trait in any useful fashion.
To use such a trait, you need to know that you never ask the question
twice, first for an incomplete
type and then for a complete type. The existing type traits don't do
that, they will do a static_assert
on the completeness and that's the end of it if the type isn't
complete - the TU is ill-formed.

There's actually no question of how a trait would behave. We know how
it behaves, it kills your cat
if you ask twice and the answer can be different. We could just as
well name it is_cat_alive. It's not quite
the Schödinger's cat; you can ask once. If you complete the cat and
ask again, you kill the cat,
as IFNDR then renders all of your program UB.

A facility like this can't be a template. And you wouldn't be able to
use it to specialize your own templates in
two different ways.

Received on 2021-11-12 03:48:39