Forward declaration and std::future

Jonathan Wakely jwakely.gcc@gmail.com
Mon Sep 13 08:52:15 GMT 2021


On Mon, 13 Sept 2021 at 09:33, Evgen Bodunov <evgen@globus.software> wrote:
>
> > On 12.09.2021, at 22:04, Jonathan Wakely via Libstdc++ <libstdc++@gcc.gnu.org> wrote:
> >
> > On Sun, 12 Sep 2021, 19:30 Evgen Bodunov, <evgen@globus.software> wrote:
> >>
> >> Please, could you refer exact part and version of the standard?
> >>
> >
> > Please reply to the mailing list, not just to me.
> >
> > Every version of the standard has the same requirement, see
> > http://eel.is/c++draft/requirements#res.on.functions-2.5
> >
> > std::promise requires its result type to be destructible. We are allowed to
> > assert that by using is_destructible because we can assume the type is
> > complete, because [res.on.functions] says it must be.
> >
> > In a correct program, the assertion will not fail.
>
> Thank you for the detailed response. For some reason I expected that if there is not enough
> type data to compile the code correctly, there would be an error from the compiler, not from
> static_assert. As for example in case of inheritance or creating objects from a type that was
> forward declared. And in this case there is an error saying that the class doesn't have a
> destructor, although it actually exists and this is confusing.


The relevant errors are:

error: static assertion failed: template argument must be a complete
class or an unbounded array
error: static assertion failed: result type must be destructible

Neither of these says there is no destructor. It says the type is
incomplete, and not destructible. You cannot tell if a type is
destructible if it's incomplete, because you can't tell if it has a
deleted or private/protected destructor, because it's incomplete.


More information about the Libstdc++ mailing list