Attempting to upgrade code from fedora 30 to fedora 32. With GCC 10 on f32 programs fail to compile that include <any> before <nlohmann/json.hpp>. With GCC 9.3.1 on f30 (and an older version 3.7.0) the provided example compiles.
[~]$ g++ --version
g++ (GCC) 10.0.1 20200328 (Red Hat 10.0.1-0.11)
[~]$ sudo dnf list --installed | grep json-devel
json-devel.x86_64 3.7.3-2.fc32
With GCC 10 attempt to compile the provided example
g++ --std=c++17 -o test test.cppWhere test.cpp is the following
#include <any>
#include <nlohmann/json.hpp>
using namespace nlohmann;
int main() {
json j;
return 0;
}
Compiles
In file included from /usr/include/c++/10/bits/move.h:57,
from /usr/include/c++/10/bits/nested_exception.h:40,
from /usr/include/c++/10/exception:148,
from /usr/include/c++/10/new:41,
from /usr/include/c++/10/any:37,
from test.cpp:1:
/usr/include/c++/10/type_traits: In instantiation of ‘struct std::is_constructible<nlohmann::basic_json<>, const nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long int, long unsigned int, double, std::allocator, nlohmann::adl_serializer>&>’:
/usr/include/nlohmann/json.hpp:11120:79: required by substitution of ‘template<class ... Args, typename std::enable_if<std::is_constructible<nlohmann::basic_json<>, Args ...>::value, int>::type <anonymous> > nlohmann::detail::json_ref<nlohmann::basic_json<> >::json_ref(Args&& ...) [with Args = {const nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long int, long unsigned int, double, std::allocator, nlohmann::adl_serializer>&}; typename std::enable_if<std::is_constructible<nlohmann::basic_json<>, Args ...>::value, int>::type <anonymous> = <missing>]’
/usr/include/c++/10/type_traits:901:30: required from ‘struct std::__is_constructible_impl<nlohmann::basic_json<>, const nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long int, long unsigned int, double, std::allocator, nlohmann::adl_serializer>&>’
/usr/include/c++/10/type_traits:930:12: required from ‘struct std::__is_copy_constructible_impl<nlohmann::basic_json<>, true>’
/usr/include/c++/10/type_traits:936:12: required from ‘struct std::is_copy_constructible<nlohmann::basic_json<> >’
/usr/include/c++/10/type_traits:138:12: [ skipping 2 instantiation contexts, use -ftemplate-backtrace-limit=0 to disable ]
/usr/include/c++/10/type_traits:2657:31: required by substitution of ‘template<class _Tp, class> static std::true_type std::__swappable_details::__do_is_swappable_impl::__test(int) [with _Tp = nlohmann::basic_json<>; <template-parameter-1-2> = <missing>]’
/usr/include/c++/10/type_traits:2681:35: required from ‘struct std::__is_swappable_impl<nlohmann::basic_json<> >’
/usr/include/c++/10/type_traits:2707:12: required from ‘struct std::is_swappable<nlohmann::basic_json<> >’
/usr/include/c++/10/type_traits:2727:26: required from ‘constexpr const bool std::is_swappable_v<nlohmann::basic_json<> >’
/usr/include/c++/10/optional:1201:51: required by substitution of ‘template<class _Tp> std::enable_if_t<(!(is_move_constructible_v<_Tp> && is_swappable_v<_Tp>))> std::swap(std::optional<_Tp>&, std::optional<_Tp>&) [with _Tp = nlohmann::basic_json<>]’
/usr/include/nlohmann/json.hpp:22677:1: required from here
/usr/include/c++/10/type_traits:906:12: error: invalid use of incomplete type ‘struct std::__is_constructible_impl<nlohmann::basic_json<>, const nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long int, long unsigned int, double, std::allocator, nlohmann::adl_serializer>&>’
906 | struct is_constructible
| ^~~~~~~~~~~~~~~~
/usr/include/c++/10/type_traits:900:12: note: declaration of ‘struct std::__is_constructible_impl<nlohmann::basic_json<>, const nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long int, long unsigned int, double, std::allocator, nlohmann::adl_serializer>&>’
900 | struct __is_constructible_impl
| ^~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/10/vector:66,
from /usr/include/c++/10/functional:62,
from /usr/include/c++/10/pstl/glue_algorithm_defs.h:13,
from /usr/include/c++/10/algorithm:74,
from /usr/include/nlohmann/json.hpp:37,
from test.cpp:2:
/usr/include/c++/10/bits/stl_uninitialized.h: In instantiation of ‘_ForwardIterator std::uninitialized_copy(_InputIterator, _InputIterator, _ForwardIterator) [with _InputIterator = __gnu_cxx::__normal_iterator<const nlohmann::basic_json<>*, std::vector<nlohmann::basic_json<>, std::allocator<nlohmann::basic_json<> > > >; _ForwardIterator = nlohmann::basic_json<>*]’:
/usr/include/c++/10/bits/stl_uninitialized.h:325:37: required from ‘_ForwardIterator std::__uninitialized_copy_a(_InputIterator, _InputIterator, _ForwardIterator, std::allocator<_Tp>&) [with _InputIterator = __gnu_cxx::__normal_iterator<const nlohmann::basic_json<>*, std::vector<nlohmann::basic_json<>, std::allocator<nlohmann::basic_json<> > > >; _ForwardIterator = nlohmann::basic_json<>*; _Tp = nlohmann::basic_json<>]’
/usr/include/c++/10/bits/stl_vector.h:555:31: required from ‘std::vector<_Tp, _Alloc>::vector(const std::vector<_Tp, _Alloc>&) [with _Tp = nlohmann::basic_json<>; _Alloc = std::allocator<nlohmann::basic_json<> >]’
/usr/include/c++/10/ext/new_allocator.h:151:4: required from ‘void __gnu_cxx::new_allocator<_Tp>::construct(_Up*, _Args&& ...) [with _Up = std::vector<nlohmann::basic_json<>, std::allocator<nlohmann::basic_json<> > >; _Args = {const std::vector<nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long int, long unsigned int, double, std::allocator, nlohmann::adl_serializer>, std::allocator<nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long int, long unsigned int, double, std::allocator, nlohmann::adl_serializer> > >&}; _Tp = std::vector<nlohmann::basic_json<>, std::allocator<nlohmann::basic_json<> > >]’
/usr/include/c++/10/bits/alloc_traits.h:507:17: required from ‘static void std::allocator_traits<std::allocator<_Tp1> >::construct(std::allocator_traits<std::allocator<_Tp1> >::allocator_type&, _Up*, _Args&& ...) [with _Up = std::vector<nlohmann::basic_json<>, std::allocator<nlohmann::basic_json<> > >; _Args = {const std::vector<nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long int, long unsigned int, double, std::allocator, nlohmann::adl_serializer>, std::allocator<nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long int, long unsigned int, double, std::allocator, nlohmann::adl_serializer> > >&}; _Tp = std::vector<nlohmann::basic_json<>, std::allocator<nlohmann::basic_json<> > >; std::allocator_traits<std::allocator<_Tp1> >::allocator_type = std::allocator<std::vector<nlohmann::basic_json<>, std::allocator<nlohmann::basic_json<> > > >]’
/usr/include/nlohmann/json.hpp:15381:35: [ skipping 2 instantiation contexts, use -ftemplate-backtrace-limit=0 to disable ]
/usr/include/nlohmann/json.hpp:16365:25: required from ‘nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer>::basic_json(const nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer>&) [with ObjectType = std::map; ArrayType = std::vector; StringType = std::__cxx11::basic_string<char>; BooleanType = bool; NumberIntegerType = long int; NumberUnsignedType = long unsigned int; NumberFloatType = double; AllocatorType = std::allocator; JSONSerializer = nlohmann::adl_serializer]’
/usr/include/nlohmann/json.hpp:4737:31: required from ‘bool nlohmann::detail::json_sax_dom_callback_parser<BasicJsonType>::end_object() [with BasicJsonType = nlohmann::basic_json<>]’
/usr/include/nlohmann/json.hpp:8847:33: required from ‘bool nlohmann::detail::parser<BasicJsonType>::sax_parse_internal(SAX*) [with SAX = nlohmann::detail::json_sax_dom_callback_parser<nlohmann::basic_json<> >; BasicJsonType = nlohmann::basic_json<>]’
/usr/include/nlohmann/json.hpp:8738:31: required from ‘void nlohmann::detail::parser<BasicJsonType>::parse(bool, BasicJsonType&) [with BasicJsonType = nlohmann::basic_json<>]’
/usr/include/nlohmann/json.hpp:20882:79: required from ‘static nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer> nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer>::parse(IteratorType, IteratorType, nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer>::parser_callback_t, bool) [with IteratorType = const char*; typename std::enable_if<std::is_base_of<std::random_access_iterator_tag, typename std::iterator_traits<_InputIterator>::iterator_category>::value, int>::type <anonymous> = 0; ObjectType = std::map; ArrayType = std::vector; StringType = std::__cxx11::basic_string<char>; BooleanType = bool; NumberIntegerType = long int; NumberUnsignedType = long unsigned int; NumberFloatType = double; AllocatorType = std::allocator; JSONSerializer = nlohmann::adl_serializer; nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer>::parser_callback_t = std::function<bool(int, nlohmann::detail::parser<nlohmann::basic_json<> >::parse_event_t, nlohmann::basic_json<>&)>]’
/usr/include/nlohmann/json.hpp:22700:42: required from here
/usr/include/c++/10/bits/stl_uninitialized.h:137:72: error: ‘value’ is not a member of ‘std::is_constructible<nlohmann::basic_json<>, const nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long int, long unsigned int, double, std::allocator, nlohmann::adl_serializer>&>’
137 | static_assert(is_constructible<_ValueType2, decltype(*__first)>::value,
| ^~~~~
develop branchThis is the same as #2129.
The next release will fix the issue, but it's not clear why. I looked a bit into it, and it's starting to look like a compiler bug to my eyes.
The error implies that some template substitution attempts are being performed before basic_json is complete, but the callstack strongly implies that this is being performed after the type is complete. Combine this with the fact that clang handles this fine and that there is no change between the current release and develop that should affect this and, yeah....
Ah my bad didn't see it since it was closed. Thanks!
@FrancoisChabot, perhaps it isn't a compiler bug. See this analysis.
Most helpful comment
@FrancoisChabot, perhaps it isn't a compiler bug. See this analysis.