From 88c92e605c7b45dba7278e27151dd19c1b378bcf Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Wed, 16 Apr 2025 16:09:21 +0200 Subject: [PATCH] Fix compilation failure and warnings with NVHPC (#4744) * :rotating_light: fix warnings Signed-off-by: Niels Lohmann * :rotating_light: fix warnings Signed-off-by: Niels Lohmann * :alembic: enable ranges support Signed-off-by: Niels Lohmann * :fire: remove ci_nvhpc job Signed-off-by: Niels Lohmann * :alembic: enable ranges support Signed-off-by: Niels Lohmann * :fire: remove ci_nvhpc job Signed-off-by: Niels Lohmann * :rotating_light: fix warning Signed-off-by: Niels Lohmann --------- Signed-off-by: Niels Lohmann --- docs/mkdocs/docs/community/quality_assurance.md | 1 + include/nlohmann/detail/output/binary_writer.hpp | 2 +- single_include/nlohmann/json.hpp | 2 +- tests/src/unit-iterators2.cpp | 3 ++- tests/src/unit-regression2.cpp | 4 ++-- tests/src/unit-udt.cpp | 6 +++++- 6 files changed, 12 insertions(+), 6 deletions(-) diff --git a/docs/mkdocs/docs/community/quality_assurance.md b/docs/mkdocs/docs/community/quality_assurance.md index 7f9402523..82e03211d 100644 --- a/docs/mkdocs/docs/community/quality_assurance.md +++ b/docs/mkdocs/docs/community/quality_assurance.md @@ -76,6 +76,7 @@ violations will result in a failed build. | GNU 13.3.0 | x86_64 | Ubuntu 22.04.1 LTS | GitHub | | GNU 14.2.0 | x86_64 | Ubuntu 22.04.1 LTS | GitHub | | GNU 14.2.0 | arm64 | Linux 6.1.100 | Cirrus CI | + | icpc (ICC) 2021.5.0 20211109 | x86_64 | Ubuntu 20.04.3 LTS | GitHub | | MSVC 19.0.24241.7 | x86 | Windows 8.1 | AppVeyor | | MSVC 19.16.27035.0 | x86 | Windows-10 (Build 14393) | AppVeyor | | MSVC 19.29.30157.0 | x86 | Windows 10 (Build 17763) | GitHub | diff --git a/include/nlohmann/detail/output/binary_writer.hpp b/include/nlohmann/detail/output/binary_writer.hpp index f81fa54c7..d1f80f877 100644 --- a/include/nlohmann/detail/output/binary_writer.hpp +++ b/include/nlohmann/detail/output/binary_writer.hpp @@ -973,9 +973,9 @@ class binary_writer if (JSON_HEDLEY_UNLIKELY(it != BasicJsonType::string_t::npos)) { JSON_THROW(out_of_range::create(409, concat("BSON key cannot contain code point U+0000 (at byte ", std::to_string(it), ")"), &j)); - static_cast(j); } + static_cast(j); return /*id*/ 1ul + name.size() + /*zero-terminator*/1u; } diff --git a/single_include/nlohmann/json.hpp b/single_include/nlohmann/json.hpp index f4e63aabe..73ecfa185 100644 --- a/single_include/nlohmann/json.hpp +++ b/single_include/nlohmann/json.hpp @@ -16712,9 +16712,9 @@ class binary_writer if (JSON_HEDLEY_UNLIKELY(it != BasicJsonType::string_t::npos)) { JSON_THROW(out_of_range::create(409, concat("BSON key cannot contain code point U+0000 (at byte ", std::to_string(it), ")"), &j)); - static_cast(j); } + static_cast(j); return /*id*/ 1ul + name.size() + /*zero-terminator*/1u; } diff --git a/tests/src/unit-iterators2.cpp b/tests/src/unit-iterators2.cpp index abf28ebe3..9e7c66f06 100644 --- a/tests/src/unit-iterators2.cpp +++ b/tests/src/unit-iterators2.cpp @@ -955,7 +955,8 @@ TEST_CASE("iterators 2") }; json j_expected{"a_key", "b_key", "c_key"}; - auto transformed = j.items() | std::views::transform([](const auto & item) + // NOLINTNEXTLINE(fuchsia-trailing-return) + auto transformed = j.items() | std::views::transform([](const auto & item) -> std::string_view { return item.key(); }); diff --git a/tests/src/unit-regression2.cpp b/tests/src/unit-regression2.cpp index 22bb8efc6..509abe986 100644 --- a/tests/src/unit-regression2.cpp +++ b/tests/src/unit-regression2.cpp @@ -566,7 +566,7 @@ TEST_CASE("regression tests 2") const auto length = 300; json dump_test; - dump_test["1"] = std::string(length, -1); + dump_test["1"] = std::string(length, static_cast(-1)); std::string expected = R"({"1":")"; for (int i = 0; i < length; ++i) @@ -583,7 +583,7 @@ TEST_CASE("regression tests 2") const auto length = 500; json dump_test; - dump_test["1"] = std::string(length, -2); + dump_test["1"] = std::string(length, static_cast(-2)); std::string expected = R"({"1":")"; for (int i = 0; i < length; ++i) diff --git a/tests/src/unit-udt.cpp b/tests/src/unit-udt.cpp index bc6bb7dc0..1caf1bbf5 100644 --- a/tests/src/unit-udt.cpp +++ b/tests/src/unit-udt.cpp @@ -841,7 +841,7 @@ class Evil public: Evil() = default; template - Evil(T t) : m_i(sizeof(t)) + Evil(const T& t) : m_i(sizeof(t)) { static_cast(t); // fix MSVC's C4100 warning } @@ -863,6 +863,10 @@ TEST_CASE("Issue #924") // silence Wunused-template warnings Evil e(1); CHECK(e.m_i >= 0); + + // suppress warning: function "::Evil::Evil(T) [with T=std::string]" was declared but never referenced [declared_but_not_referenced] + Evil e2(std::string("foo")); + CHECK(e2.m_i >= 0); } TEST_CASE("Issue #1237")