From f257ac3373ed0f285153dd110b65e5b579953025 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Wed, 30 Sep 2026 17:58:51 +0200 Subject: [PATCH] Remove the GCC C++20 -Wignored-attributes pragma in json.hpp The pragma (added in #5164) claimed to work around the C++ modules redefinition errors of #5103, but #5103 is about hard errors (e.g. "redefinition of std::__is_constant_evaluated()", conflicting std::integral_constant) that ignoring a warning cannot suppress; they are traced to GCC PR 124430 and reproduce with or instead of json.hpp too. A GCC 16.2 -std=gnu++20 -fmodules build following #5103's repro steps still fails with the pragma in place, and a build of all test TUs with GCC_CXXFLAGS (which enable -Wignored-attributes) and the pragma removed produces no such warning. The block only hid a warning class from GCC C++20 users while suggesting #5103 was handled. Overlaps #5610, whose hunks touch the closing half of this pragma to insert the json_literals.hpp include. Signed-off-by: Niels Lohmann #5725 item 9 --- include/nlohmann/json.hpp | 15 --------------- single_include/nlohmann/json.hpp | 15 --------------- 2 files changed, 30 deletions(-) diff --git a/include/nlohmann/json.hpp b/include/nlohmann/json.hpp index 500fcddf2..0bf165748 100644 --- a/include/nlohmann/json.hpp +++ b/include/nlohmann/json.hpp @@ -18,16 +18,6 @@ #ifndef INCLUDE_NLOHMANN_JSON_HPP_ #define INCLUDE_NLOHMANN_JSON_HPP_ -// Workaround for GCC template redefinition errors in C++ modules -// When nlohmann/json.hpp is included in a C++20 module preamble after -// other module imports, GCC may report spurious redefinition errors for -// STL templates. These pragmas suppress those false positives. -// See: https://github.com/nlohmann/json/issues/5103 -#if defined(__GNUC__) && !defined(__clang__) && __cplusplus >= 202002L - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wignored-attributes" -#endif - #include // all_of, find, for_each, none_of #include // nullptr_t, ptrdiff_t, size_t #include // hash, less @@ -6619,9 +6609,4 @@ struct formatter // NOLINT(cert-dcl58-c #include -// End of GCC diagnostic pragmas for C++ modules support -#if defined(__GNUC__) && !defined(__clang__) && __cplusplus >= 202002L - #pragma GCC diagnostic pop -#endif - #endif // INCLUDE_NLOHMANN_JSON_HPP_ diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index e9d09c478..a7b129cce 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -18,16 +18,6 @@ #ifndef INCLUDE_NLOHMANN_JSON_HPP_ #define INCLUDE_NLOHMANN_JSON_HPP_ -// Workaround for GCC template redefinition errors in C++ modules -// When nlohmann/json.hpp is included in a C++20 module preamble after -// other module imports, GCC may report spurious redefinition errors for -// STL templates. These pragmas suppress those false positives. -// See: https://github.com/nlohmann/json/issues/5103 -#if defined(__GNUC__) && !defined(__clang__) && __cplusplus >= 202002L - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wignored-attributes" -#endif - #include // all_of, find, for_each, none_of #include // nullptr_t, ptrdiff_t, size_t #include // hash, less @@ -32919,9 +32909,4 @@ struct formatter // NOLINT(cert-dcl58-c -// End of GCC diagnostic pragmas for C++ modules support -#if defined(__GNUC__) && !defined(__clang__) && __cplusplus >= 202002L - #pragma GCC diagnostic pop -#endif - #endif // INCLUDE_NLOHMANN_JSON_HPP_