json icon indicating copy to clipboard operation
json copied to clipboard

Support "import" statement in module interface files.

Open nicolasjinchereau opened this issue 2 years ago • 7 comments

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

nicolasjinchereau avatar Apr 06 '22 07:04 nicolasjinchereau

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)

gregmarr avatar Apr 06 '22 13:04 gregmarr

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;

nicolasjinchereau avatar Apr 06 '22 16:04 nicolasjinchereau

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.

gregmarr avatar Apr 06 '22 18:04 gregmarr

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....

theambient avatar Apr 11 '22 17:04 theambient

Same here, on Visual Studio 2022 preview.

Leadwerks avatar Jul 08 '22 08:07 Leadwerks

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.

falbrechtskirchinger avatar Jul 08 '22 09:07 falbrechtskirchinger

Maybe related to #3974 and fixed by #3975.

nlohmann avatar Mar 13 '23 11:03 nlohmann