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

Incomplete type with json_fwd.hpp #1232

Closed
reinerh opened this issue Sep 10, 2018 · 2 comments
Closed

Incomplete type with json_fwd.hpp #1232

reinerh opened this issue Sep 10, 2018 · 2 comments
Labels
kind: question solution: proposed fix a fix for the issue has been proposed and waits for confirmation

Comments

@reinerh
Copy link

reinerh commented Sep 10, 2018

  • What is the issue you have?

When I change #include <nlohmann/json.hpp> to <nlohmann/json_fwd.hpp> in my header (and include json.hpp in my cpp file), it no longer compiles.

  • Please describe the steps to reproduce the issue. Can you provide a small but working code example?

test.h:

#ifndef TEST_H
#define TEST_H

#include <nlohmann/json_fwd.hpp>

using json = nlohmann::json;

class Foo {
  public:
    json foo;
};

#endif // TEST_H

test.cpp

#include "test.h"

#include <nlohmann/json.hpp>

int main()
{
	Foo x;
	return 0;
}
  • What is the expected behavior?

That the file compiles (which it does when I include json.hpp instead of json_fwd.hpp in the header file).

  • And what is the actual behavior instead?
$ g++ test.cpp 
In file included from test.cpp:1:
test.h:10:10: error: field ‘foo’ has incomplete type ‘json’ {aka ‘nlohmann::basic_json<>’}
     json foo;
          ^~~
In file included from test.h:4,
                 from test.cpp:1:
/usr/include/nlohmann/json_fwd.hpp:37:7: note: declaration of ‘using json = using json = class nlohmann::basic_json<>’ {aka ‘class nlohmann::basic_json<>’}
 class basic_json;
       ^~~~~~~~~~

gcc 8.2.0 on Debian Linux.

  • Did you use a released version of the library or the version from the develop branch?

Release 3.2.0.

100% tests passed, 0 tests failed out of 80

@theodelrieu
Copy link
Contributor

It is normal, attributes must be complete types. You can workaround that by having json* instead.

@reinerh
Copy link
Author

reinerh commented Sep 10, 2018

Ah, you are right. thanks.
I guess I have to continue using the big header then. :)

@reinerh reinerh closed this as completed Sep 10, 2018
@nlohmann nlohmann added kind: question solution: proposed fix a fix for the issue has been proposed and waits for confirmation labels Sep 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind: question solution: proposed fix a fix for the issue has been proposed and waits for confirmation
Projects
None yet
Development

No branches or pull requests

3 participants