-
-
Notifications
You must be signed in to change notification settings - Fork 6.8k
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
GCC 10: Compilation error when including any before including json header in C++17 mode #2129
Comments
For reference, here is the error message from godbolt:
|
It seem like it doesn't happen with the develop branch. Here's a compiler explorer like that shows this. I'm quite unsure what caused this. I'm glad this is fixed now. I would be ready to close this issue unless someone would like to take the time to explain what happened there. I tried to find an explanation but didn't found any. |
I neither have a clue nor could reproduce it with the develop branch either... |
Was this maybe fixed by #2034 ? I experienced that issue also without including , most standard library headers caused this, but it was fixed by #2034. EDIT: godbolt to prove my point: https://godbolt.org/z/4Pswt6 Left is the version without #2034 merged, right is after the merge. |
As I have no clue and this is a nice explanation, I am happy to close this issue. Thanks for digging into this! |
I suppose I found the answer to that mind-boggling question. I'm not a compiler expert though so take that into consideration. MINIMAL CODE EXAMPLEFirst of all, enclosed is the minimal code of single header where I removed everything that wasn't necessary to reproduce the bug: file json.hpp #include <string>
#include <type_traits>
#include <utility>
template<typename>
class basic_json;
using json = basic_json<std::string>;
class json_ref
{
public:
template <typename T,
bool = std::is_constructible<json, T>::value>
json_ref(T &&){}
};
template<typename>
class basic_json
{
public:
basic_json(json_ref) {}
};
namespace std {
template<>
void swap<json>(json&, json&) noexcept {}
} // namespace std file main.cpp #include <any>
#include "json.hpp"
int main() {} OBSERVATIONSThen I started playing with it and I discovered strange relations and how the code could be fixed by:
ANALYSIS AND EXPLANATIONFrom
|
Maybe #2176 is related to this. |
Thank you for this explanation. This is why I stumbled across the |
:) |
Please note the following resolution from Jonathan Wakely on the GCC issue:
I think I failed to think about a possible "infinite"/incomplete template instantiation here when I wrote the initial version of the |
Resolves nlohmann::json conflict with g++-10: nlohmann/json#2129
What is the issue you have?
A compilation error just including parts of the standard library and this library in a specific order when using C++17 and GCC 10.
Please describe the steps to reproduce the issue.
Consider the following file:
When compiling it in C++17 mode, it won't compile with GCC 10
Here's a compile explorer link that shows the issue.
When changing
<any>
to<variant>
, there is no issue. I don't know if any other standard header causes this bug.When putting the
#include <any>
after#include <nlohmann/json>
, it compiles. DEMO.What is the expected behavior?
It should compile.
And what is the actual behavior instead?
It shows very strange errors and fail to compile.
Which compiler and operating system are you using?
Which version of the library did you use?
develop
branchIf you experience a compilation error: can you compile and run the unit tests?
I had issues with some CMake related tests but it seem unrelated to this bug.
The text was updated successfully, but these errors were encountered: