Fix -Weffc++ errors in the #5198 locale test

GCC's -Weffc++ (an error in ci_test_gcc and ci_test_standards_gcc)
rejected LocaleSwitchingSax: it has a pointer data member but does not
declare its copy operations, and its vectors are not initialized in the
member initializer list. Store the locale name as a std::string and give
the vectors brace initializers, like SaxEventLogger in
unit-deserialization.cpp.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
Niels Lohmann
2026-09-28 04:19:20 +02:00
parent cfe7c9e732
commit a3c2b0897e
+4 -4
View File
@@ -236,7 +236,7 @@ struct LocaleSwitchingSax final: public nlohmann::json_sax<json>
}
bool start_array(std::size_t /*val*/) override
{
switched = std::setlocale(LC_NUMERIC, locale_after_open) != nullptr;
switched = std::setlocale(LC_NUMERIC, locale_after_open.c_str()) != nullptr;
return true;
}
bool end_array() override
@@ -248,10 +248,10 @@ struct LocaleSwitchingSax final: public nlohmann::json_sax<json>
return false;
}
const char* locale_after_open;
std::string locale_after_open;
bool switched = false;
std::vector<json::number_float_t> values;
std::vector<json::string_t> strings;
std::vector<json::number_float_t> values {}; // NOLINT(readability-redundant-member-init)
std::vector<json::string_t> strings {}; // NOLINT(readability-redundant-member-init)
};
} // namespace