Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support "import" statement in module interface files. #3424

Open
2 tasks
nicolasjinchereau opened this issue Apr 6, 2022 · 7 comments
Open
2 tasks

Support "import" statement in module interface files. #3424

nicolasjinchereau opened this issue Apr 6, 2022 · 7 comments

Comments

@nicolasjinchereau
Copy link

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

@gregmarr
Copy link
Contributor

gregmarr commented Apr 6, 2022

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)

@nicolasjinchereau
Copy link
Author

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;

@gregmarr
Copy link
Contributor

gregmarr commented Apr 6, 2022

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.

@theambient
Copy link

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

@Leadwerks
Copy link

Same here, on Visual Studio 2022 preview.

@falbrechtskirchinger
Copy link
Contributor

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.

@nlohmann
Copy link
Owner

Maybe related to #3974 and fixed by #3975.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants