Forward declaration and std::future
Jonathan Wakely
jwakely.gcc@gmail.com
Sun Sep 12 18:19:11 GMT 2021
On Sun, 12 Sep 2021, 10:36 Evgen Bodunov, <evgen@globus.software> wrote:
> Hello everyone,
>
> During development of valhalla routing project I stumbled upon compilation
> error on gcc + libstdc++ 11 and newer when std::future constructed from
> forward declared class. Live example is there:
> https://godbolt.org/z/rEx3Eonsz It builds on gcc prior to v11. and on any
> clang with libc++.
>
> /opt/compiler-explorer/gcc-11.1.0/include/c++/11.1.0/type_traits: In
> instantiation of 'struct std::is_destructible<test_data>':
> /opt/compiler-explorer/gcc-11.1.0/include/c++/11.1.0/future:1065:21:
> required from 'class std::promise<test_data>'
> <source>:8:29: required from here
> /opt/compiler-explorer/gcc-11.1.0/include/c++/11.1.0/type_traits:849:52:
> error: static assertion failed: template argument must be a complete class
> or an unbounded array
> 849 |
> static_assert(std::__is_complete_or_unbounded(__type_identity<_Tp>{}),
> |
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
> /opt/compiler-explorer/gcc-11.1.0/include/c++/11.1.0/type_traits:849:52:
> note: 'std::__is_complete_or_unbounded<std::__type_identity<test_data>
> >((std::__type_identity<test_data>{}, std::__type_identity<test_data>()))'
> evaluates to false
> In file included from <source>:1:
> /opt/compiler-explorer/gcc-11.1.0/include/c++/11.1.0/future: In
> instantiation of 'class std::promise<test_data>':
> <source>:8:29: required from here
> /opt/compiler-explorer/gcc-11.1.0/include/c++/11.1.0/future:1065:21:
> error: static assertion failed: result type must be destructible
> 1065 | static_assert(is_destructible<_Res>{},
> | ^~~~~~~~~~~~~~~~~~~~~~~
> /opt/compiler-explorer/gcc-11.1.0/include/c++/11.1.0/future:1065:21: note:
> 'std::is_destructible<test_data>{}' evaluates to false
> Compiler returned: 1
>
> Is that static assert is really required? May be then it should correctly
> process forward declared types?
>
The standard says your code has undefined behaviour. The assertion is
pointing out your mistake.
More information about the Libstdc++
mailing list