Closed
Description
Compiling this code:
#include <nlohmann/json.hpp>
int main()
{
nlohmann::ordered_json metadata;
metadata.erase("key");
return 0;
}
with following command:
/usr/local/cuda-11.4/bin/nvcc -I/path/to/nlohmann-json/include/ -c file.cu -o a.out
fails with:
(const BasicJsonType &) [with BasicJsonType=nlohmann::json]"
detected during instantiation of "std::size_t nlohmann::detail::hash(const BasicJsonType &) [with BasicJsonType=nlohmann::json]"
/path/to/nlohmann-json/include/nlohmann/json.hpp(8709): here
/path/to/nlohmann-json/include/nlohmann/ordered_map.hpp: In instantiation of ‘typename std::vector<std::pair<const _Key, _Tp>, Allocator>::size_type nlohmann::ordered_map<Key, T, IgnoredLess, Allocator>::erase(const Key&) [with Key = std::__cxx11::basic_string<char>; T = nlohmann::basic_json<nlohmann::ordered_map>; IgnoredLess = std::less<>; Allocator = std::allocator<std::pair<const std::__cxx11::basic_string<char>, nlohmann::basic_json<nlohmann::ordered_map> > >; typename std::vector<std::pair<const _Key, _Tp>, Allocator>::size_type = long unsigned int]’:
/path/to/nlohmann-json/include/nlohmann/json.hpp:4241:37: required from ‘nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType>::size_type nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType>::erase(const typename ObjectType<StringType, nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType>, std::less<void>, AllocatorType<std::pair<const StringType, nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType> > > >::key_type&) [with ObjectType = nlohmann::ordered_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; BinaryType = std::vector<unsigned char>; nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType>::size_type = long unsigned int; typename ObjectType<StringType, nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType>, std::less<void>, AllocatorType<std::pair<const StringType, nlohmann::basic_json<ObjectType, ArrayType, StringType, BooleanType, NumberIntegerType, NumberUnsignedType, NumberFloatType, AllocatorType, JSONSerializer, BinaryType> > > >::key_type = std::__cxx11::basic_string<char>]’
file.cu:7:21: required from here
/path/to/nlohmann-json/include/nlohmann/ordered_map.hpp:92:6: error: object type ‘std::pair<const std::__cxx11::basic_string<char>, nlohmann::basic_json<nlohmann::ordered_map> >’ does not match destructor name ~‘value_type’
92 | it->~value_type(); // Destroy but keep allocation
| ^
make: *** [Makefile:13: toy] Error 1
nlohmann json version: 3.9.1
gcc version: 9.3
Tested with nvcc version 11.0, 11.1, 11.2, 11.3, and 11.4 with same error. This code compiles fine with gcc. Possibly an nvcc
/C++ bug, but there might be a solution in nlohmann/json side?