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

json.hpp compilation issue with other typedefs with same name #1642

Closed
kevinlul opened this issue Jun 16, 2019 · 3 comments · Fixed by #1643
Closed

json.hpp compilation issue with other typedefs with same name #1642

kevinlul opened this issue Jun 16, 2019 · 3 comments · Fixed by #1643
Assignees
Labels
kind: bug release item: 🐛 bug fix solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Milestone

Comments

@kevinlul
Copy link
Contributor

The issue is similar to #606 and #1530: a compilation error involving json.hpp, with < being interpreted as a template instead of "less than"

nlohmann-json

Essentially, other typedefs with the same name as the ones used by the library are taken as reference when templating, which happens often under using namespace

This is confirmed to happen with GCC 7.4.0 on Ubuntu and GCC 9.1.0 on macOS Mojave, compiling against the version from apt-get and brew respectively.

A fix would be wrapping the comparisons with parentheses.

Also discovered by @edo9300 and @DyXel

kevinlul added a commit to kevinlul/json that referenced this issue Jun 16, 2019
While in our case, only the string case was affected, to be safe and allow the library to work with other unforeseen cases, all of the cases have been wrapped with parentheses.

Thank you @DyXel and @edo9300
kevinlul added a commit to kevinlul/json that referenced this issue Jun 16, 2019
While in our case, only the string case was affected, to be safe and allow the library to work with other unforeseen cases, all of the cases have been wrapped with parentheses.

Thank you @DyXel and @edo9300
@nickaein
Copy link
Contributor

Thanks for reporting the issue!

This is a reoccurring issue (e.g. #590, #606, #1530) which strangely, current CI builds haven't detected. For instance, the library are being built with GCC 4 through GCC 9 in Travis CI yet this error remains uncaught.

Can you give more details on the build environment so the error can be reproduced and prevented in the future by setting up a regression build? It would be kind of you if you could reproduce the error on https://godbolt.org (you can set compiler version and build flags there).

@edo9300
Copy link

edo9300 commented Jun 17, 2019

@nickaein i made a sample scenario where this happens https://godbolt.org/z/iHJVjA

template <typename T>
class string {
};
#include <nlohmann/json.hpp>
int main() {
	return 0;
}

you can replace that templated class with any of the classes used by this library, and get the same error. Weirdly enough this doesn't happen when compiling for windows https://godbolt.org/z/aoAxd0

@nickaein
Copy link
Contributor

@edo9300: Thanks for the example! We might have to add something like this as a regression test.

@kevinlul: I've just noticed you have already opened an PR for this issue. Thanks for that! You might want to add a Fixes #1642 phrase (or other keywords mentioned here) in the description of PR so that gets linked to this issue and automatically close the issue when merged.

@nlohmann nlohmann added the solution: proposed fix a fix for the issue has been proposed and waits for confirmation label Jun 25, 2019
kevinlul added a commit to kevinlul/json that referenced this issue Jun 29, 2019
kevinlul added a commit to kevinlul/json that referenced this issue Jun 30, 2019
nlohmann added a commit that referenced this issue Jul 1, 2019
Fix json.hpp compilation issue with other typedefs with same name (Issue #1642)
@nlohmann nlohmann self-assigned this Jul 1, 2019
@nlohmann nlohmann added this to the Release 3.6.2 milestone Jul 1, 2019
@nlohmann nlohmann modified the milestones: Release 3.6.2, Release 3.7.0 Jul 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: bug release item: 🐛 bug fix solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants