1
0
mirror of https://github.com/nlohmann/json.git synced 2026-07-29 15:13:04 +04:00

Avoid C-style array in test to satisfy clang-tidy avoid-c-arrays

clang-tidy's cppcoreguidelines/hicpp/modernize-avoid-c-arrays checks
flagged the char raw_data[] declaration used to reproduce the
lvalue-only non-const ADL begin/end scenario. Use std::string instead
and take a mutable pointer via &raw_data[0], which is the standard
way to get a non-const char* into a string's buffer under C++11
(std::string::data() only returns non-const in C++17 and later).

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
This commit is contained in:
Niels Lohmann
2026-07-10 07:22:45 +02:00
parent 366b00e871
commit 252bb1e671
+2 -2
View File
@@ -73,8 +73,8 @@ char* end(MyContainerNonConstADL& c)
TEST_CASE("Custom container non-member non-const begin/end")
{
// Container with lvalue-only non-const ADL begin/end (bug reproduction)
char raw_data[] = "[1,2,3,4]";
MyContainerNonConstADL data{raw_data, sizeof(raw_data) - 1};
std::string raw_data = "[1,2,3,4]";
MyContainerNonConstADL data{&raw_data[0], raw_data.size()}; // NOLINT(readability-container-data-pointer)
const json as_json = json::parse(data);
CHECK(as_json.at(0) == 1);
CHECK(as_json.at(1) == 2);