Skip to content

Incomplete type with json_fwd.hpp #1232

Description

@reinerh
  • 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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions