nlohmann / json

JSON for Modern C++
https://json.nlohmann.me
MIT License
42.01k stars 6.63k forks source link

Doesn't seem to work with Clang C++20 modules #4002

Open rnikander opened 1 year ago

rnikander commented 1 year ago

Description

I'm not sure if this is a bug in Clang, or in this library. I've been using C++20 modules there but they do have some problems.

https://godbolt.org/z/ndqTvEzGj

I linked to Clang 16.0.0, because as of right now, the trunk is segfaulting. It's been doing that for a few days now. But normally I use Clang trunk when I can.

Reproduction steps

Look at the godbolt example, it shows the error. It's a minimal example with no other code in the files.

Expected vs. actual results

This cryptic compiler error shouldn't be happening.

Minimal code example

https://godbolt.org/z/ndqTvEzGj

Error messages

/opt/compiler-explorer/clang-16.0.0/bin/clang++ --gcc-toolchain=/opt/compiler-explorer/gcc-12.2.0   -fcolor-diagnostics -fno-crash-diagnostics -std=c++20 -isystem/opt/compiler-explorer/libs/nlohmann_json/trunk/single_include -g -MD -MT CMakeFiles/mod_json_bug.dir/Mod1_Impl.cc.o -MF CMakeFiles/mod_json_bug.dir/Mod1_Impl.cc.o.d @CMakeFiles/mod_json_bug.dir/Mod1_Impl.cc.o.modmap -o CMakeFiles/mod_json_bug.dir/Mod1_Impl.cc.o -c /app/Mod1_Impl.cc
In file included from /app/Mod1_Impl.cc:2:
/opt/compiler-explorer/libs/nlohmann_json/trunk/single_include/nlohmann/json.hpp:14438:13: error: no matching function for call to 'unescape'
            detail::unescape(reference_token);
            ^~~~~~~~~~~~~~~~
/opt/compiler-explorer/libs/nlohmann_json/trunk/single_include/nlohmann/json.hpp:13782:28: note: in instantiation of member function 'nlohmann::json_pointer<std::basic_string<char>>::split' requested here
        : reference_tokens(split(s))
                           ^
/opt/compiler-explorer/libs/nlohmann_json/trunk/single_include/nlohmann/json.hpp:24402:12: note: in instantiation of member function 'nlohmann::json_pointer<std::basic_string<char>>::json_pointer' requested here
    return nlohmann::json::json_pointer(std::string(s, n));
           ^

Compiler and operating system

linux, clang, or macos clang

Library version

6af826d0bdb55e4b69e3ad817576745335f243ca via conan

Validation

LecrisUT commented 1 year ago

Could this be an issue with #include orders or is it a missing macro/concept or some other defintion somewhere? I had an issue with #include<memory> needing to be included before #include<filesystem>. Maybe there is something similar happening here.

I do confirm that I get the same error and only when using modules. Navigating the traceback, I don't see anything that should be creating such an issue. I find it weird because when I replace template<>static void unescape(StringType& s) with an explicit static void unescape(std::string& s) the problem does not manifest. I have tried moving around the code, but that makes no difference. I have even tested with static_assert(std::same_as<string_t,std::string>); and that does not fail. This could be a clang bug if you can rope some of them to take a look at this.