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

Unknown Type Name clang error when using NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE #2313

Closed
2 of 5 tasks
stoeckley opened this issue Jul 26, 2020 · 2 comments
Closed
2 of 5 tasks
Assignees
Labels
kind: bug solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Milestone

Comments

@stoeckley
Copy link

stoeckley commented Jul 26, 2020

What is the issue you have?

Clang reports:

error: unknown type name 's'

with this code:

struct Foo {
	string s;
};

NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Foo, s)

(in the same namespace)

more specifically:

main.cpp:24:37: error: unknown type name 's'
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Foo, s)
                                            ^  (the '^' appears under the 's')
main.cpp:26:1: error: expected function body after function declarator

Compiled as so:

clang++ -std=c++17 main.cpp -o build/main -O3

~/projects/jsontest clang --version
Apple clang version 11.0.3 (clang-1103.0.32.62)
Target: x86_64-apple-darwin19.5.0
Thread model: posix

Which version of the library did you use?

3.8.0

  • latest release version 3.7.3
  • other release - please state the version: 3.8.0
  • the develop branch

If you experience a compilation error: can you compile and run the unit tests?

  • yes
  • no - please copy/paste the error message below
@nlohmann
Copy link
Owner

Please try again with the latest develop branch. This issue should have been fixed lately.

The following code works with Apple clang version 12.0.0 (clang-1200.0.22.19).

#include <iostream>
#include <nlohmann/json.hpp>

using json = nlohmann::json;

struct Foo {
    std::string s;
};

NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Foo, s)

int main()
{
    Foo foo;
    foo.s = "Hello, world!";
    
    json j = foo;
    std::cout << j << std::endl;
}

Output:

{"s":"Hello, world!"}

@stoeckley
Copy link
Author

You are correct!! Thanks.

@nlohmann nlohmann added the solution: proposed fix a fix for the issue has been proposed and waits for confirmation label Jul 26, 2020
@nlohmann nlohmann self-assigned this Jul 26, 2020
@nlohmann nlohmann added this to the Release 3.9.0 milestone Jul 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: bug solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Projects
None yet
Development

No branches or pull requests

2 participants