Skip to content

Commit 58bd97e

Browse files
Add clang-tools to required tools for ci_static_analysis_clang (nlohmann#3724)
* 💚 add clang-tools to required tools for ci_static_analysis_clang * 🚨 update Clang-Tidy warning selection * 🚨 fix Clang-Tidy warnings * 🚨 fix Clang-Tidy warnings * 🚨 fix Clang-Tidy warnings * 🚨 fix Clang-Tidy warnings * 🚨 fix Clang-Tidy warnings * 🚨 fix Clang-Tidy warnings * 🚨 fix Clang-Tidy warnings * 🚨 fix Clang-Tidy warnings * 🚨 fix Clang-Tidy warnings * 🚨 fix Clang-Tidy warnings * 🚨 fix Clang-Tidy warnings (nlohmann#3738) * ⏪ revert fix * ⏪ revert fix * 🚨 fix Clang-Tidy warnings (nlohmann#3739) Co-authored-by: Florian Albrechtskirchinger <falbrechtskirchinger@gmail.com>
1 parent 307c053 commit 58bd97e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+2757
-2626
lines changed

.clang-tidy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Checks: '*,
66
-bugprone-easily-swappable-parameters,
77
-cert-err58-cpp,
88
-concurrency-mt-unsafe,
9+
-cppcoreguidelines-avoid-const-or-ref-data-members,
910
-cppcoreguidelines-avoid-goto,
1011
-cppcoreguidelines-avoid-magic-numbers,
1112
-cppcoreguidelines-avoid-non-const-global-variables,

.github/workflows/ubuntu.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ jobs:
7373
target: [ci_clang_tidy, ci_test_clang_sanitizer, ci_clang_analyze]
7474
steps:
7575
- name: Install git
76-
run: apt-get update ; apt-get install -y git
76+
run: apt-get update ; apt-get install -y git clang-tools
7777
- uses: actions/checkout@v3
7878
- name: Get latest CMake and ninja
7979
uses: lukka/get-cmake@latest

include/nlohmann/detail/exceptions.hpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -149,17 +149,17 @@ class parse_error : public exception
149149
template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value, int> = 0>
150150
static parse_error create(int id_, const position_t& pos, const std::string& what_arg, BasicJsonContext context)
151151
{
152-
std::string w = concat(exception::name("parse_error", id_), "parse error",
153-
position_string(pos), ": ", exception::diagnostics(context), what_arg);
152+
const std::string w = concat(exception::name("parse_error", id_), "parse error",
153+
position_string(pos), ": ", exception::diagnostics(context), what_arg);
154154
return {id_, pos.chars_read_total, w.c_str()};
155155
}
156156

157157
template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value, int> = 0>
158158
static parse_error create(int id_, std::size_t byte_, const std::string& what_arg, BasicJsonContext context)
159159
{
160-
std::string w = concat(exception::name("parse_error", id_), "parse error",
161-
(byte_ != 0 ? (concat(" at byte ", std::to_string(byte_))) : ""),
162-
": ", exception::diagnostics(context), what_arg);
160+
const std::string w = concat(exception::name("parse_error", id_), "parse error",
161+
(byte_ != 0 ? (concat(" at byte ", std::to_string(byte_))) : ""),
162+
": ", exception::diagnostics(context), what_arg);
163163
return {id_, byte_, w.c_str()};
164164
}
165165

@@ -193,7 +193,7 @@ class invalid_iterator : public exception
193193
template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value, int> = 0>
194194
static invalid_iterator create(int id_, const std::string& what_arg, BasicJsonContext context)
195195
{
196-
std::string w = concat(exception::name("invalid_iterator", id_), exception::diagnostics(context), what_arg);
196+
const std::string w = concat(exception::name("invalid_iterator", id_), exception::diagnostics(context), what_arg);
197197
return {id_, w.c_str()};
198198
}
199199

@@ -211,7 +211,7 @@ class type_error : public exception
211211
template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value, int> = 0>
212212
static type_error create(int id_, const std::string& what_arg, BasicJsonContext context)
213213
{
214-
std::string w = concat(exception::name("type_error", id_), exception::diagnostics(context), what_arg);
214+
const std::string w = concat(exception::name("type_error", id_), exception::diagnostics(context), what_arg);
215215
return {id_, w.c_str()};
216216
}
217217

@@ -228,7 +228,7 @@ class out_of_range : public exception
228228
template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value, int> = 0>
229229
static out_of_range create(int id_, const std::string& what_arg, BasicJsonContext context)
230230
{
231-
std::string w = concat(exception::name("out_of_range", id_), exception::diagnostics(context), what_arg);
231+
const std::string w = concat(exception::name("out_of_range", id_), exception::diagnostics(context), what_arg);
232232
return {id_, w.c_str()};
233233
}
234234

@@ -245,7 +245,7 @@ class other_error : public exception
245245
template<typename BasicJsonContext, enable_if_t<is_basic_json_context<BasicJsonContext>::value, int> = 0>
246246
static other_error create(int id_, const std::string& what_arg, BasicJsonContext context)
247247
{
248-
std::string w = concat(exception::name("other_error", id_), exception::diagnostics(context), what_arg);
248+
const std::string w = concat(exception::name("other_error", id_), exception::diagnostics(context), what_arg);
249249
return {id_, w.c_str()};
250250
}
251251

include/nlohmann/detail/input/binary_reader.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ class binary_reader
330330
{
331331
std::array<char, 3> cr{{}};
332332
static_cast<void>((std::snprintf)(cr.data(), cr.size(), "%.2hhX", static_cast<unsigned char>(element_type))); // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg)
333-
std::string cr_str{cr.data()};
333+
const std::string cr_str{cr.data()};
334334
return sax->parse_error(element_type_parse_position, cr_str,
335335
parse_error::create(114, element_type_parse_position, concat("Unsupported BSON record type 0x", cr_str), nullptr));
336336
}
@@ -2265,7 +2265,7 @@ class binary_reader
22652265
exception_message(input_format, concat("expected '#' after type information; last byte: 0x", last_token), "size"), nullptr));
22662266
}
22672267

2268-
bool is_error = get_ubjson_size_value(result.first, is_ndarray);
2268+
const bool is_error = get_ubjson_size_value(result.first, is_ndarray);
22692269
if (input_format == input_format_t::bjdata && is_ndarray)
22702270
{
22712271
if (inside_ndarray)
@@ -2280,7 +2280,7 @@ class binary_reader
22802280

22812281
if (current == '#')
22822282
{
2283-
bool is_error = get_ubjson_size_value(result.first, is_ndarray);
2283+
const bool is_error = get_ubjson_size_value(result.first, is_ndarray);
22842284
if (input_format == input_format_t::bjdata && is_ndarray)
22852285
{
22862286
return sax->parse_error(chars_read, get_token_string(), parse_error::create(112, chars_read,

include/nlohmann/detail/json_pointer.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ class json_pointer
230230
const char* p = s.c_str();
231231
char* p_end = nullptr;
232232
errno = 0; // strtoull doesn't reset errno
233-
unsigned long long res = std::strtoull(p, &p_end, 10); // NOLINT(runtime/int)
233+
const unsigned long long res = std::strtoull(p, &p_end, 10); // NOLINT(runtime/int)
234234
if (p == p_end // invalid input or empty string
235235
|| errno == ERANGE // out of range
236236
|| JSON_HEDLEY_UNLIKELY(static_cast<std::size_t>(p_end - p) != s.size())) // incomplete read

include/nlohmann/detail/macro_scope.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@
396396

397397
#define NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(Type, ...) \
398398
friend void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \
399-
friend void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { Type nlohmann_json_default_obj; NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM_WITH_DEFAULT, __VA_ARGS__)) }
399+
friend void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { const Type nlohmann_json_default_obj{}; NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM_WITH_DEFAULT, __VA_ARGS__)) }
400400

401401
/*!
402402
@brief macro
@@ -409,7 +409,7 @@
409409

410410
#define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Type, ...) \
411411
inline void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \
412-
inline void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { Type nlohmann_json_default_obj; NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM_WITH_DEFAULT, __VA_ARGS__)) }
412+
inline void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { const Type nlohmann_json_default_obj{}; NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM_WITH_DEFAULT, __VA_ARGS__)) }
413413

414414

415415
// inspired from https://stackoverflow.com/a/26745591

include/nlohmann/detail/output/binary_writer.hpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -661,18 +661,18 @@ class binary_writer
661661
}
662662
else if (N <= (std::numeric_limits<std::uint16_t>::max)())
663663
{
664-
std::uint8_t output_type = use_ext
665-
? 0xC8 // ext 16
666-
: 0xC5; // bin 16
664+
const std::uint8_t output_type = use_ext
665+
? 0xC8 // ext 16
666+
: 0xC5; // bin 16
667667

668668
oa->write_character(to_char_type(output_type));
669669
write_number(static_cast<std::uint16_t>(N));
670670
}
671671
else if (N <= (std::numeric_limits<std::uint32_t>::max)())
672672
{
673-
std::uint8_t output_type = use_ext
674-
? 0xC9 // ext 32
675-
: 0xC6; // bin 32
673+
const std::uint8_t output_type = use_ext
674+
? 0xC9 // ext 32
675+
: 0xC6; // bin 32
676676

677677
oa->write_character(to_char_type(output_type));
678678
write_number(static_cast<std::uint32_t>(N));
@@ -1258,8 +1258,8 @@ class binary_writer
12581258
*/
12591259
static std::size_t calc_bson_object_size(const typename BasicJsonType::object_t& value)
12601260
{
1261-
std::size_t document_size = std::accumulate(value.begin(), value.end(), static_cast<std::size_t>(0),
1262-
[](size_t result, const typename BasicJsonType::object_t::value_type & el)
1261+
const std::size_t document_size = std::accumulate(value.begin(), value.end(), static_cast<std::size_t>(0),
1262+
[](size_t result, const typename BasicJsonType::object_t::value_type & el)
12631263
{
12641264
return result += calc_bson_element_size(el.first, el.second);
12651265
});

include/nlohmann/detail/output/serializer.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -926,7 +926,7 @@ class serializer
926926
? (byte & 0x3fu) | (codep << 6u)
927927
: (0xFFu >> type) & (byte);
928928

929-
std::size_t index = 256u + static_cast<size_t>(state) * 16u + static_cast<size_t>(type);
929+
const std::size_t index = 256u + static_cast<size_t>(state) * 16u + static_cast<size_t>(type);
930930
JSON_ASSERT(index < 400);
931931
state = utf8d[index];
932932
return state;

include/nlohmann/json.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4718,7 +4718,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
47184718
}
47194719

47204720
// make sure the top element of the pointer exists
4721-
json_pointer top_pointer = ptr.top();
4721+
json_pointer const top_pointer = ptr.top();
47224722
if (top_pointer != ptr)
47234723
{
47244724
result.at(top_pointer);
@@ -4880,7 +4880,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
48804880
json_pointer from_ptr(from_path);
48814881

48824882
// the "from" location must exist - use at()
4883-
basic_json v = result.at(from_ptr);
4883+
basic_json const v = result.at(from_ptr);
48844884

48854885
// The move operation is functionally identical to a
48864886
// "remove" operation on the "from" location, followed
@@ -4897,7 +4897,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec
48974897
const json_pointer from_ptr(from_path);
48984898

48994899
// the "from" location must exist - use at()
4900-
basic_json v = result.at(from_ptr);
4900+
basic_json const v = result.at(from_ptr);
49014901

49024902
// The copy is functionally identical to an "add"
49034903
// operation at the target location using the value

0 commit comments

Comments
 (0)