Support "import" statement in module interface files.
Description
I'm using MSVC 2022 with /std:c++20.
I'm trying to import single_include version 3.10.5 into my module interface file (*.ixx).
import <json.hpp>;
However, I am receiving an error.
json.hpp(18037,17): error C2976: 'nlohmann::adl_serializer': too few template arguments
Including the file in the global module fragment does work:
module;
#include <json.hpp>
export module MyModule;
...
However, exporting only nlohmann::json with a using statement produces errors about dependent types, so I would like to export the whole import.
export import <json.hpp>;
Reproduction steps
Try to import json.hpp into a module interface file.
Expected vs. actual results
Does not compile.
Minimal code example
No response
Error messages
`json.hpp(18037,17): error C2976: 'nlohmann::adl_serializer': too few template arguments`
Compiler and operating system
MSVC 2022
Library version
3.10.5
Validation
- [ ] The bug also occurs if the latest version from the
developbranch is used. - [ ] I can successfully compile and run the unit tests.
What is line 18037 in your version? I downloaded the json.hpp from that tag and it's a break in this constructor, which makes no sense.
/// @brief create a JSON value from an existing one
/// @sa https://json.nlohmann.me/api/basic_json/basic_json/
template < typename BasicJsonType,
detail::enable_if_t <
detail::is_basic_json<BasicJsonType>::value&& !std::is_same<basic_json, BasicJsonType>::value, int > = 0 >
basic_json(const BasicJsonType& val)
That constructor is on line 18050 for me. The constructor right above it makes use of JSONSerializer.
I think the error may be coming from the forward declaration of basic_json on line 3353.
...
template<typename T, typename SFINAE = void> class JSONSerializer =
adl_serializer,
class BinaryType = std::vector<std::uint8_t>>
class basic_json;
template<typename T = void, typename SFINAE = void>
struct adl_serializer;
Not sure how you can have too few arguments for a template that has all its arguments defaulted.
Also had the same issue, both with header units and modules (VS 2022).
If i provide second argument to adp_serializer as void cl.exe crashes....
Same here, on Visual Studio 2022 preview.
FYI, PR #3518 is failing CI because of the same error message in a different context (and on older MSVC compilers). I haven't looked into it any further because I'm not actively seeking to have that PR merged at this time, but it might be worth reconsidering if it can incidentally fix this issue.
Maybe related to #3974 and fixed by #3975.