Skip to content

Commit 1101f0e

Browse files
committed
🚨 fix warnings
1 parent eacf4f4 commit 1101f0e

File tree

11 files changed

+38
-42
lines changed

11 files changed

+38
-42
lines changed

.clang-tidy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Checks: '*,
1414
-fuchsia-overloaded-operator,
1515
-google-explicit-constructor,
1616
-google-readability-function-size,
17+
-google-runtime-int,
1718
-google-runtime-references,
1819
-hicpp-avoid-goto,
1920
-hicpp-explicit-conversions,

include/nlohmann/detail/conversions/from_json.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ void from_json(const BasicJsonType& j, ConstructibleObjectType& obj)
269269
}
270270

271271
ConstructibleObjectType ret;
272-
auto inner_object = j.template get_ptr<const typename BasicJsonType::object_t*>();
272+
const auto* inner_object = j.template get_ptr<const typename BasicJsonType::object_t*>();
273273
using value_type = typename ConstructibleObjectType::value_type;
274274
std::transform(
275275
inner_object->begin(), inner_object->end(),

include/nlohmann/detail/conversions/to_json.hpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,15 @@ struct external_constructor<value_t::binary>
7373
static void construct(BasicJsonType& j, const typename BasicJsonType::binary_t& b)
7474
{
7575
j.m_type = value_t::binary;
76-
typename BasicJsonType::binary_t value{b};
77-
j.m_value = value;
76+
j.m_value = typename BasicJsonType::binary_t(b);
7877
j.assert_invariant();
7978
}
8079

8180
template<typename BasicJsonType>
8281
static void construct(BasicJsonType& j, typename BasicJsonType::binary_t&& b)
8382
{
8483
j.m_type = value_t::binary;
85-
typename BasicJsonType::binary_t value{std::move(b)};
86-
j.m_value = value;
84+
j.m_value = typename BasicJsonType::binary_t(std::move(b));;
8785
j.assert_invariant();
8886
}
8987
};
@@ -322,9 +320,9 @@ void to_json(BasicJsonType& j, typename BasicJsonType::object_t&& obj)
322320
template <
323321
typename BasicJsonType, typename T, std::size_t N,
324322
enable_if_t < !std::is_constructible<typename BasicJsonType::string_t,
325-
const T(&)[N]>::value,
323+
const T(&)[N]>::value, // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
326324
int > = 0 >
327-
void to_json(BasicJsonType& j, const T(&arr)[N])
325+
void to_json(BasicJsonType& j, const T(&arr)[N]) // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
328326
{
329327
external_constructor<value_t::array>::construct(j, arr);
330328
}

include/nlohmann/detail/json_pointer.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ class json_pointer
399399
*/
400400
BasicJsonType& get_and_create(BasicJsonType& j) const
401401
{
402-
auto result = &j;
402+
auto* result = &j;
403403

404404
// in case no reference tokens exist, return a reference to the JSON value
405405
// j which will be overwritten by a primitive value

include/nlohmann/detail/output/binary_writer.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class binary_writer
3636
3737
@param[in] adapter output adapter to write to
3838
*/
39-
explicit binary_writer(output_adapter_t<CharType> adapter) : oa(adapter)
39+
explicit binary_writer(output_adapter_t<CharType> adapter) : oa(std::move(adapter))
4040
{
4141
JSON_ASSERT(oa);
4242
}

include/nlohmann/json.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2937,7 +2937,7 @@ class basic_json
29372937
static_assert(std::is_default_constructible<ValueType>::value,
29382938
"types must be DefaultConstructible when used with get()");
29392939

2940-
ValueType ret;
2940+
ValueType ret{};
29412941
JSONSerializer<ValueType>::from_json(*this, ret);
29422942
return ret;
29432943
}
@@ -3044,10 +3044,10 @@ class basic_json
30443044

30453045
template <
30463046
typename T, std::size_t N,
3047-
typename Array = T (&)[N],
3047+
typename Array = T (&)[N], // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
30483048
detail::enable_if_t <
30493049
detail::has_from_json<basic_json_t, Array>::value, int > = 0 >
3050-
Array get_to(T (&v)[N]) const
3050+
Array get_to(T (&v)[N]) const // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
30513051
noexcept(noexcept(JSONSerializer<Array>::from_json(
30523052
std::declval<const basic_json_t&>(), v)))
30533053
{
@@ -8753,7 +8753,7 @@ struct less<::nlohmann::detail::value_t>
87538753
*/
87548754
template<>
87558755
inline void swap<nlohmann::json>(nlohmann::json& j1, nlohmann::json& j2) noexcept(
8756-
is_nothrow_move_constructible<nlohmann::json>::value&&
8756+
is_nothrow_move_constructible<nlohmann::json>::value&& // NOLINT(misc-redundant-expression)
87578757
is_nothrow_move_assignable<nlohmann::json>::value
87588758
)
87598759
{

single_include/nlohmann/json.hpp

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3751,7 +3751,7 @@ void from_json(const BasicJsonType& j, ConstructibleObjectType& obj)
37513751
}
37523752

37533753
ConstructibleObjectType ret;
3754-
auto inner_object = j.template get_ptr<const typename BasicJsonType::object_t*>();
3754+
const auto* inner_object = j.template get_ptr<const typename BasicJsonType::object_t*>();
37553755
using value_type = typename ConstructibleObjectType::value_type;
37563756
std::transform(
37573757
inner_object->begin(), inner_object->end(),
@@ -4144,17 +4144,15 @@ struct external_constructor<value_t::binary>
41444144
static void construct(BasicJsonType& j, const typename BasicJsonType::binary_t& b)
41454145
{
41464146
j.m_type = value_t::binary;
4147-
typename BasicJsonType::binary_t value{b};
4148-
j.m_value = value;
4147+
j.m_value = typename BasicJsonType::binary_t(b);
41494148
j.assert_invariant();
41504149
}
41514150

41524151
template<typename BasicJsonType>
41534152
static void construct(BasicJsonType& j, typename BasicJsonType::binary_t&& b)
41544153
{
41554154
j.m_type = value_t::binary;
4156-
typename BasicJsonType::binary_t value{std::move(b)};
4157-
j.m_value = value;
4155+
j.m_value = typename BasicJsonType::binary_t(std::move(b));;
41584156
j.assert_invariant();
41594157
}
41604158
};
@@ -4393,9 +4391,9 @@ void to_json(BasicJsonType& j, typename BasicJsonType::object_t&& obj)
43934391
template <
43944392
typename BasicJsonType, typename T, std::size_t N,
43954393
enable_if_t < !std::is_constructible<typename BasicJsonType::string_t,
4396-
const T(&)[N]>::value,
4394+
const T(&)[N]>::value, // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
43974395
int > = 0 >
4398-
void to_json(BasicJsonType& j, const T(&arr)[N])
4396+
void to_json(BasicJsonType& j, const T(&arr)[N]) // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
43994397
{
44004398
external_constructor<value_t::array>::construct(j, arr);
44014399
}
@@ -12055,7 +12053,7 @@ class json_pointer
1205512053
*/
1205612054
BasicJsonType& get_and_create(BasicJsonType& j) const
1205712055
{
12058-
auto result = &j;
12056+
auto* result = &j;
1205912057

1206012058
// in case no reference tokens exist, return a reference to the JSON value
1206112059
// j which will be overwritten by a primitive value
@@ -12877,7 +12875,7 @@ class binary_writer
1287712875

1287812876
@param[in] adapter output adapter to write to
1287912877
*/
12880-
explicit binary_writer(output_adapter_t<CharType> adapter) : oa(adapter)
12878+
explicit binary_writer(output_adapter_t<CharType> adapter) : oa(std::move(adapter))
1288112879
{
1288212880
JSON_ASSERT(oa);
1288312881
}
@@ -19565,7 +19563,7 @@ class basic_json
1956519563
static_assert(std::is_default_constructible<ValueType>::value,
1956619564
"types must be DefaultConstructible when used with get()");
1956719565

19568-
ValueType ret;
19566+
ValueType ret{};
1956919567
JSONSerializer<ValueType>::from_json(*this, ret);
1957019568
return ret;
1957119569
}
@@ -19672,10 +19670,10 @@ class basic_json
1967219670

1967319671
template <
1967419672
typename T, std::size_t N,
19675-
typename Array = T (&)[N],
19673+
typename Array = T (&)[N], // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
1967619674
detail::enable_if_t <
1967719675
detail::has_from_json<basic_json_t, Array>::value, int > = 0 >
19678-
Array get_to(T (&v)[N]) const
19676+
Array get_to(T (&v)[N]) const // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
1967919677
noexcept(noexcept(JSONSerializer<Array>::from_json(
1968019678
std::declval<const basic_json_t&>(), v)))
1968119679
{
@@ -25381,7 +25379,7 @@ struct less<::nlohmann::detail::value_t>
2538125379
*/
2538225380
template<>
2538325381
inline void swap<nlohmann::json>(nlohmann::json& j1, nlohmann::json& j2) noexcept(
25384-
is_nothrow_move_constructible<nlohmann::json>::value&&
25382+
is_nothrow_move_constructible<nlohmann::json>::value&& // NOLINT(misc-redundant-expression)
2538525383
is_nothrow_move_assignable<nlohmann::json>::value
2538625384
)
2538725385
{

test/src/unit-cbor.cpp

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2029,20 +2029,18 @@ TEST_CASE("CBOR roundtrips" * doctest::skip())
20292029
SECTION("input from flynn")
20302030
{
20312031
// most of these are excluded due to differences in key order (not a real problem)
2032-
auto exclude_packed = std::set<std::string>
2033-
{
2034-
TEST_DATA_DIRECTORY "/json.org/1.json",
2035-
TEST_DATA_DIRECTORY "/json.org/2.json",
2036-
TEST_DATA_DIRECTORY "/json.org/3.json",
2037-
TEST_DATA_DIRECTORY "/json.org/4.json",
2038-
TEST_DATA_DIRECTORY "/json.org/5.json",
2039-
TEST_DATA_DIRECTORY "/json_testsuite/sample.json", // kills AppVeyor
2040-
TEST_DATA_DIRECTORY "/json_tests/pass1.json",
2041-
TEST_DATA_DIRECTORY "/regression/working_file.json",
2042-
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object.json",
2043-
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_duplicated_key.json",
2044-
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_long_strings.json",
2045-
};
2032+
std::set<std::string> exclude_packed;
2033+
exclude_packed.insert(TEST_DATA_DIRECTORY "/json.org/1.json");
2034+
exclude_packed.insert(TEST_DATA_DIRECTORY "/json.org/2.json");
2035+
exclude_packed.insert(TEST_DATA_DIRECTORY "/json.org/3.json");
2036+
exclude_packed.insert(TEST_DATA_DIRECTORY "/json.org/4.json");
2037+
exclude_packed.insert(TEST_DATA_DIRECTORY "/json.org/5.json");
2038+
exclude_packed.insert(TEST_DATA_DIRECTORY "/json_testsuite/sample.json"); // kills AppVeyor
2039+
exclude_packed.insert(TEST_DATA_DIRECTORY "/json_tests/pass1.json");
2040+
exclude_packed.insert(TEST_DATA_DIRECTORY "/regression/working_file.json");
2041+
exclude_packed.insert(TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object.json");
2042+
exclude_packed.insert(TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_duplicated_key.json");
2043+
exclude_packed.insert(TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_long_strings.json");
20462044

20472045
for (std::string filename :
20482046
{

test/src/unit-msgpack.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ TEST_CASE("MessagePack")
446446

447447
SECTION("-32768..-129 (int 16)")
448448
{
449-
for (int16_t i = -32768; i <= -129; ++i)
449+
for (int16_t i = -32768; i <= int16_t(-129); ++i)
450450
{
451451
CAPTURE(i)
452452

test/src/unit-regression1.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ using foo_json = nlohmann::basic_json<std::map, std::vector, std::string, bool,
115115

116116
namespace
117117
{
118-
struct nocopy
118+
struct nocopy // NOLINT(cppcoreguidelines-special-member-functions,hicpp-special-member-functions)
119119
{
120120
nocopy() = default;
121121
nocopy(const nocopy&) = delete;

0 commit comments

Comments
 (0)