The following piece of code compiles fine in g++ 8.3 and 7.4 when -std=c++17 is set:
#include <any>
#include <tuple>
#include <vector>
int main()
{
std::vector<std::tuple<std::any>> f2;
f2.emplace_back(42);
return 0;
}
VS2017 works well, too.
But with g++ 9.1 I see this error:
In file included from /usr/include/c++/9/bits/move.h:55,
from /usr/include/c++/9/bits/nested_exception.h:40,
from /usr/include/c++/9/exception:144,
from /usr/include/c++/9/new:40,
from /usr/include/c++/9/any:37,
from a.cpp:1:
/usr/include/c++/9/type_traits: In instantiation of ‘struct std::__and_<std::is_constructible<std::tuple<std::any>, std::tuple<std::any>&&>, std::__is_nt_constructible_impl<std::tuple<std::any>, std::tuple<std::any>&&> >’:
/usr/include/c++/9/type_traits:974:12: required from ‘struct std::is_nothrow_constructible<std::tuple<std::any>, std::tuple<std::any>&&>’
/usr/include/c++/9/type_traits:1005:12: required from ‘struct std::__is_nothrow_move_constructible_impl<std::tuple<std::any>, true>’
/usr/include/c++/9/type_traits:1011:12: required from ‘struct std::is_nothrow_move_constructible<std::tuple<std::any> >’
/usr/include/c++/9/any:95:67: required by substitution of ‘template<class _Tp, class _Safe, bool _Fits> using _Internal = std::integral_constant<bool, (_Safe::value && _Fits)> [with _Tp = std::tuple<std::any>; _Safe = std::is_nothrow_move_constructible<std::tuple<std::any> >; bool _Fits = ((sizeof (std::tuple<std::any>) <= sizeof (std::any::_Storage)) && (8 <= 8))]’
/usr/include/c++/9/any:104:13: required by substitution of ‘template<class _Tp> using _Manager = std::conditional_t<std::any::_Internal<_Tp>::value, std::any::_Manager_internal<_Tp>, std::any::_Manager_external<_Tp> > [with _Tp = std::tuple<std::any>]’
/usr/include/c++/9/any:180:8: [ skipping 3 instantiation contexts, use -ftemplate-backtrace-limit=0 to disable ]
/usr/include/c++/9/type_traits:925:12: required from ‘struct std::is_move_constructible<std::tuple<std::any> >’
/usr/include/c++/9/bits/alloc_traits.h:619:12: required from ‘struct std::__is_move_insertable<std::allocator<std::tuple<std::any> > >’
/usr/include/c++/9/bits/stl_vector.h:446:28: required from ‘static constexpr bool std::vector<_Tp, _Alloc>::_S_use_relocate() [with _Tp = std::tuple<std::any>; _Alloc = std::allocator<std::tuple<std::any> >]’
/usr/include/c++/9/bits/vector.tcc:459:44: required from ‘void std::vector<_Tp, _Alloc>::_M_realloc_insert(std::vector<_Tp, _Alloc>::iterator, _Args&& ...) [with _Args = {int}; _Tp = std::tuple<std::any>; _Alloc = std::allocator<std::tuple<std::any> >; std::vector<_Tp, _Alloc>::iterator = __gnu_cxx::__normal_iterator<std::tuple<std::any>*, std::vector<std::tuple<std::any> > >; typename std::_Vector_base<_Tp, _Alloc>::pointer = std::tuple<std::any>*]’
/usr/include/c++/9/bits/vector.tcc:121:4: required from ‘std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::emplace_back(_Args&& ...) [with _Args = {int}; _Tp = std::tuple<std::any>; _Alloc = std::allocator<std::tuple<std::any> >; std::vector<_Tp, _Alloc>::reference = std::tuple<std::any>&]’
a.cpp:8:21: required from here
/usr/include/c++/9/type_traits:131:12: error: incomplete type ‘std::is_constructible<std::tuple<std::any>, std::tuple<std::any>&&>’ used in nested name specifier
131 | struct __and_<_B1, _B2>
| ^~~~~~~~~~~~~~~~
Is there something wrong with the code or is it a g++-9 issue?
It is a gcc problem, which was fixed after version 9.5 (Bug report). We can reproduce this problem in all 9.1 - 9.4 versions. Also, we can produce success build in 8.X versions.
Compared versions 8.5 (OK), 9.1 (NOK) and 10.1 (OK) in compiler explorer. All is flaged with -std=c++17
without any other optimizations.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With