From e872ffdcf202862e1bde1ea5718b2059f122cea5 Mon Sep 17 00:00:00 2001 From: Niels Lohmann Date: Sat, 10 Oct 2026 08:38:01 +0200 Subject: [PATCH] Make the value of the custom test key types private clang-tidy (cppcoreguidelines-non-private-member-variables-in-classes) rejects the protected member; the derived key types use a protected accessor instead. Signed-off-by: Niels Lohmann --- tests/src/custom_key_test.hpp | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/tests/src/custom_key_test.hpp b/tests/src/custom_key_test.hpp index 28cb31060..224517b0f 100644 --- a/tests/src/custom_key_test.hpp +++ b/tests/src/custom_key_test.hpp @@ -53,6 +53,12 @@ class key_base } protected: + const std::string& str() const noexcept + { + return m_value; + } + + private: std::string m_value; }; @@ -65,12 +71,12 @@ class key_full : public key_base operator std::string() const { - return m_value; + return str(); } friend bool operator==(const key_full& lhs, const key_full& rhs) { - return lhs.m_value == rhs.m_value; + return lhs.str() == rhs.str(); } }; @@ -83,7 +89,7 @@ class key_no_eq : public key_base operator std::string() const { - return m_value; + return str(); } }; @@ -96,7 +102,7 @@ class key_explicit : public key_base explicit operator std::string() const { - return m_value; + return str(); } }; @@ -109,7 +115,7 @@ class key_to_json : public key_base const std::string& value() const { - return m_value; + return str(); } }; @@ -128,17 +134,17 @@ class key_c_str : public key_base const std::string& value() const { - return m_value; + return str(); } std::size_t size() const { - return m_value.size(); + return str().size(); } const char* c_str() const { - return m_value.c_str(); + return str().c_str(); } }; @@ -356,7 +362,7 @@ void test_parse() { text += "{\"k" + std::to_string(i) + "\":"; } - text += "1"; + text += '1'; text.append(depth, '}'); CHECK(custom_key_test::check_deep(J::parse(text), depth, false)); }