Skip to content

Declare the namespace-scope constants in to_chars.hpp inline - #5776

Merged
nlohmann merged 1 commit into
reamalgamate-5740from
fix-c5260-inline-constexpr
Oct 7, 2026
Merged

nlohmann merged 1 commit into
reamalgamate-5740from
fix-c5260-inline-constexpr

Conversation

@nlohmann

@nlohmann nlohmann commented Oct 7, 2026 •

Copy link
Copy Markdown
Owner

MSVC reports warning C5260 ("the constant variable … has internal linkage in an included header file context, but external linkage in imported header unit context") for to_chars.hpp when the library is used as a header unit or through a module, see #4826.

The warning comes from kAlpha and kGamma, the only constexpr variables at namespace scope in that file. The other constants there are function-local or static members. This declares the two constants JSON_INLINE_VARIABLE constexpr, which the library already uses for static_const. It expands to inline from C++17 on and to nothing before, so C++11 and C++14 are unchanged.

Not verified on MSVC locally. Checked with Apple Clang at C++11, C++17, and C++20 for both headers (-Wall -Wextra -Werror, dumping floating-point numbers).

API impact

No breaking changes. The two constants are in nlohmann::detail::dtoa_impl and keep their values.

Written by Claude Code.

🤖 Generated with Claude Code

MSVC warns with C5260 that kAlpha and kGamma have internal linkage when
the header is used as a header unit or through a module. JSON_INLINE_VARIABLE
makes them inline variables from C++17 on.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
@nlohmann
nlohmann force-pushed the fix-c5260-inline-constexpr branch from f04d147 to 079b83b Compare October 7, 2026 07:01
@nlohmann
nlohmann changed the base branch from develop to reamalgamate-5740 October 7, 2026 07:01
@nlohmann
nlohmann added this pull request to stack #5778 October 7, 2026 07:02
@nlohmann nlohmann added this to the Release 3.13.0 milestone Oct 7, 2026
@nlohmann
nlohmann merged commit 30e542e into develop Oct 7, 2026
4 of 174 checks passed
@nlohmann
nlohmann deleted the fix-c5260-inline-constexpr branch October 7, 2026 07:03
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

Successfully merging this pull request may close these issues.

1 participant