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

error: ‘BasicJsonType’ in namespace ‘::’ does not name a type #1051

Closed
simulationcloud opened this issue Apr 11, 2018 · 9 comments
Closed

Comments

@simulationcloud
Copy link

I get this error when compiling with nvcc, which is using g++6.4.1. I am specifying the --std=c++11 flag.

The version of nlohmann/json is 3.1.2.

Any help would be greatly appreciated!

@nlohmann
Copy link
Owner

Could you indicate the line where the error occurs or paste the complete error message here? What was the code you tried to compile?

@simulationcloud
Copy link
Author

/home/ec2-user/dev/john/Flow360_3.26.2018/json/include/nlohmann/detail/iterators/iter_impl.hpp:46:11: error:
This is the error I get by only including the header file #include "nlohmann/json.hpp":

‘BasicJsonType’ in namespace ‘::’ does not name a type
friend BasicJsonType;
^~~~~~~~~~~~~

I reverted to version 2.1.2 and got it to compile, but I would like to use the latest version.

@theodelrieu
Copy link
Contributor

Seems like a compiler bug to me...

Could you try patching the iter_impl.hpp?

using J = BasicJsonType;
friend J;

@simulationcloud
Copy link
Author

hmm. Same thing with the patch:
/home/ec2-user/dev/john/Flow360_3.26.2018/json/include/nlohmann/detail/iterators/iter_impl.hpp:48:11: error: ‘BasicJsonType’ in namespace ‘::’ does not name a type
friend J;

@theodelrieu
Copy link
Contributor

This is weird, I guess it's the same problem if you change the name of the template parameter directly?

@simulationcloud
Copy link
Author

I think it's a bug with nvcc. If I move the function to a separate cpp file and compile it only with gcc, it works.

@nlohmann
Copy link
Owner

Thanks for reporting back!

@schwarzschild-radius
Copy link

is there anyway to make it work with nvcc?

@schwarzschild-radius
Copy link

This answer in Stackoverflow solves the problem. Adding a wrapper around the BasicJsonType works with nvcc and gcc.

template<typename T>
struct BasicJsonType_wrapper{
    typedef T type;
};

template<typename BasicJsonType>
class iter_impl
{
    /// allow basic_json to access private members
    friend iter_impl<typename std::conditional<std::is_const<BasicJsonType>::value, typename     std::remove_const<BasicJsonType>::type, const BasicJsonType>::type>;
    // friend BasicJsonType;
    friend class BasicJsonType_wrapper<BasicJsonType>::type;
    friend iteration_proxy<iter_impl>;

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

No branches or pull requests

4 participants