If compiling with modules enabled with clang, #pragma once is used across all headers -- in other words, only the first header with #pragma once in it will be included, and the rest ignored. Headers in nlohmann use #pragma once, and thus the library is difficult or impossible to be used in a modular codebase.
is sufficient to expose the issue if not using the "single header" version. Otherwise, combining it with any other header using #pragma once is sufficient.
Expected vs. actual results
The library should compile, but it errors out with bogus messages.
Minimal code example
No response
Error messages
No response
Compiler and operating system
clang
Library version
b2306145e1789368e6f261680e8dc007e91cc986
Validation
[X] The bug also occurs if the latest version from the develop branch is used.
Description
If compiling with modules enabled with clang,
#pragma once
is used across all headers -- in other words, only the first header with#pragma once
in it will be included, and the rest ignored. Headers innlohmann
use#pragma once
, and thus the library is difficult or impossible to be used in a modular codebase.The upstream bug is https://github.com/llvm/llvm-project/issues/38554.
The workaround is to use traditional
#ifndef
include guards instead.Reproduction steps
is sufficient to expose the issue if not using the "single header" version. Otherwise, combining it with any other header using
#pragma once
is sufficient.Expected vs. actual results
The library should compile, but it errors out with bogus messages.
Minimal code example
No response
Error messages
No response
Compiler and operating system
clang
Library version
b2306145e1789368e6f261680e8dc007e91cc986
Validation
develop
branch is used.