Skip to content

Commit

Permalink
🚨 fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
nlohmann committed Jan 29, 2021
1 parent eacf4f4 commit 1101f0e
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 42 deletions.
1 change: 1 addition & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Checks: '*,
-fuchsia-overloaded-operator,
-google-explicit-constructor,
-google-readability-function-size,
-google-runtime-int,
-google-runtime-references,
-hicpp-avoid-goto,
-hicpp-explicit-conversions,
Expand Down
2 changes: 1 addition & 1 deletion include/nlohmann/detail/conversions/from_json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ void from_json(const BasicJsonType& j, ConstructibleObjectType& obj)
}

ConstructibleObjectType ret;
auto inner_object = j.template get_ptr<const typename BasicJsonType::object_t*>();
const auto* inner_object = j.template get_ptr<const typename BasicJsonType::object_t*>();
using value_type = typename ConstructibleObjectType::value_type;
std::transform(
inner_object->begin(), inner_object->end(),
Expand Down
10 changes: 4 additions & 6 deletions include/nlohmann/detail/conversions/to_json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,15 @@ struct external_constructor<value_t::binary>
static void construct(BasicJsonType& j, const typename BasicJsonType::binary_t& b)
{
j.m_type = value_t::binary;
typename BasicJsonType::binary_t value{b};
j.m_value = value;
j.m_value = typename BasicJsonType::binary_t(b);
j.assert_invariant();
}

template<typename BasicJsonType>
static void construct(BasicJsonType& j, typename BasicJsonType::binary_t&& b)
{
j.m_type = value_t::binary;
typename BasicJsonType::binary_t value{std::move(b)};
j.m_value = value;
j.m_value = typename BasicJsonType::binary_t(std::move(b));;
j.assert_invariant();
}
};
Expand Down Expand Up @@ -322,9 +320,9 @@ void to_json(BasicJsonType& j, typename BasicJsonType::object_t&& obj)
template <
typename BasicJsonType, typename T, std::size_t N,
enable_if_t < !std::is_constructible<typename BasicJsonType::string_t,
const T(&)[N]>::value,
const T(&)[N]>::value, // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
int > = 0 >
void to_json(BasicJsonType& j, const T(&arr)[N])
void to_json(BasicJsonType& j, const T(&arr)[N]) // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
{
external_constructor<value_t::array>::construct(j, arr);
}
Expand Down
2 changes: 1 addition & 1 deletion include/nlohmann/detail/json_pointer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ class json_pointer
*/
BasicJsonType& get_and_create(BasicJsonType& j) const
{
auto result = &j;
auto* result = &j;

// in case no reference tokens exist, return a reference to the JSON value
// j which will be overwritten by a primitive value
Expand Down
2 changes: 1 addition & 1 deletion include/nlohmann/detail/output/binary_writer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class binary_writer
@param[in] adapter output adapter to write to
*/
explicit binary_writer(output_adapter_t<CharType> adapter) : oa(adapter)
explicit binary_writer(output_adapter_t<CharType> adapter) : oa(std::move(adapter))
{
JSON_ASSERT(oa);
}
Expand Down
8 changes: 4 additions & 4 deletions include/nlohmann/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2937,7 +2937,7 @@ class basic_json
static_assert(std::is_default_constructible<ValueType>::value,
"types must be DefaultConstructible when used with get()");

ValueType ret;
ValueType ret{};
JSONSerializer<ValueType>::from_json(*this, ret);
return ret;
}
Expand Down Expand Up @@ -3044,10 +3044,10 @@ class basic_json

template <
typename T, std::size_t N,
typename Array = T (&)[N],
typename Array = T (&)[N], // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
detail::enable_if_t <
detail::has_from_json<basic_json_t, Array>::value, int > = 0 >
Array get_to(T (&v)[N]) const
Array get_to(T (&v)[N]) const // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
noexcept(noexcept(JSONSerializer<Array>::from_json(
std::declval<const basic_json_t&>(), v)))
{
Expand Down Expand Up @@ -8753,7 +8753,7 @@ struct less<::nlohmann::detail::value_t>
*/
template<>
inline void swap<nlohmann::json>(nlohmann::json& j1, nlohmann::json& j2) noexcept(
is_nothrow_move_constructible<nlohmann::json>::value&&
is_nothrow_move_constructible<nlohmann::json>::value&& // NOLINT(misc-redundant-expression)
is_nothrow_move_assignable<nlohmann::json>::value
)
{
Expand Down
24 changes: 11 additions & 13 deletions single_include/nlohmann/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3751,7 +3751,7 @@ void from_json(const BasicJsonType& j, ConstructibleObjectType& obj)
}

ConstructibleObjectType ret;
auto inner_object = j.template get_ptr<const typename BasicJsonType::object_t*>();
const auto* inner_object = j.template get_ptr<const typename BasicJsonType::object_t*>();
using value_type = typename ConstructibleObjectType::value_type;
std::transform(
inner_object->begin(), inner_object->end(),
Expand Down Expand Up @@ -4144,17 +4144,15 @@ struct external_constructor<value_t::binary>
static void construct(BasicJsonType& j, const typename BasicJsonType::binary_t& b)
{
j.m_type = value_t::binary;
typename BasicJsonType::binary_t value{b};
j.m_value = value;
j.m_value = typename BasicJsonType::binary_t(b);
j.assert_invariant();
}

template<typename BasicJsonType>
static void construct(BasicJsonType& j, typename BasicJsonType::binary_t&& b)
{
j.m_type = value_t::binary;
typename BasicJsonType::binary_t value{std::move(b)};
j.m_value = value;
j.m_value = typename BasicJsonType::binary_t(std::move(b));;
j.assert_invariant();
}
};
Expand Down Expand Up @@ -4393,9 +4391,9 @@ void to_json(BasicJsonType& j, typename BasicJsonType::object_t&& obj)
template <
typename BasicJsonType, typename T, std::size_t N,
enable_if_t < !std::is_constructible<typename BasicJsonType::string_t,
const T(&)[N]>::value,
const T(&)[N]>::value, // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
int > = 0 >
void to_json(BasicJsonType& j, const T(&arr)[N])
void to_json(BasicJsonType& j, const T(&arr)[N]) // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
{
external_constructor<value_t::array>::construct(j, arr);
}
Expand Down Expand Up @@ -12055,7 +12053,7 @@ class json_pointer
*/
BasicJsonType& get_and_create(BasicJsonType& j) const
{
auto result = &j;
auto* result = &j;

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

@param[in] adapter output adapter to write to
*/
explicit binary_writer(output_adapter_t<CharType> adapter) : oa(adapter)
explicit binary_writer(output_adapter_t<CharType> adapter) : oa(std::move(adapter))
{
JSON_ASSERT(oa);
}
Expand Down Expand Up @@ -19565,7 +19563,7 @@ class basic_json
static_assert(std::is_default_constructible<ValueType>::value,
"types must be DefaultConstructible when used with get()");

ValueType ret;
ValueType ret{};
JSONSerializer<ValueType>::from_json(*this, ret);
return ret;
}
Expand Down Expand Up @@ -19672,10 +19670,10 @@ class basic_json

template <
typename T, std::size_t N,
typename Array = T (&)[N],
typename Array = T (&)[N], // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
detail::enable_if_t <
detail::has_from_json<basic_json_t, Array>::value, int > = 0 >
Array get_to(T (&v)[N]) const
Array get_to(T (&v)[N]) const // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays)
noexcept(noexcept(JSONSerializer<Array>::from_json(
std::declval<const basic_json_t&>(), v)))
{
Expand Down Expand Up @@ -25381,7 +25379,7 @@ struct less<::nlohmann::detail::value_t>
*/
template<>
inline void swap<nlohmann::json>(nlohmann::json& j1, nlohmann::json& j2) noexcept(
is_nothrow_move_constructible<nlohmann::json>::value&&
is_nothrow_move_constructible<nlohmann::json>::value&& // NOLINT(misc-redundant-expression)
is_nothrow_move_assignable<nlohmann::json>::value
)
{
Expand Down
26 changes: 12 additions & 14 deletions test/src/unit-cbor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2029,20 +2029,18 @@ TEST_CASE("CBOR roundtrips" * doctest::skip())
SECTION("input from flynn")
{
// most of these are excluded due to differences in key order (not a real problem)
auto exclude_packed = std::set<std::string>
{
TEST_DATA_DIRECTORY "/json.org/1.json",
TEST_DATA_DIRECTORY "/json.org/2.json",
TEST_DATA_DIRECTORY "/json.org/3.json",
TEST_DATA_DIRECTORY "/json.org/4.json",
TEST_DATA_DIRECTORY "/json.org/5.json",
TEST_DATA_DIRECTORY "/json_testsuite/sample.json", // kills AppVeyor
TEST_DATA_DIRECTORY "/json_tests/pass1.json",
TEST_DATA_DIRECTORY "/regression/working_file.json",
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object.json",
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_duplicated_key.json",
TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_long_strings.json",
};
std::set<std::string> exclude_packed;
exclude_packed.insert(TEST_DATA_DIRECTORY "/json.org/1.json");
exclude_packed.insert(TEST_DATA_DIRECTORY "/json.org/2.json");
exclude_packed.insert(TEST_DATA_DIRECTORY "/json.org/3.json");
exclude_packed.insert(TEST_DATA_DIRECTORY "/json.org/4.json");
exclude_packed.insert(TEST_DATA_DIRECTORY "/json.org/5.json");
exclude_packed.insert(TEST_DATA_DIRECTORY "/json_testsuite/sample.json"); // kills AppVeyor
exclude_packed.insert(TEST_DATA_DIRECTORY "/json_tests/pass1.json");
exclude_packed.insert(TEST_DATA_DIRECTORY "/regression/working_file.json");
exclude_packed.insert(TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object.json");
exclude_packed.insert(TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_duplicated_key.json");
exclude_packed.insert(TEST_DATA_DIRECTORY "/nst_json_testsuite/test_parsing/y_object_long_strings.json");

for (std::string filename :
{
Expand Down
2 changes: 1 addition & 1 deletion test/src/unit-msgpack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ TEST_CASE("MessagePack")

SECTION("-32768..-129 (int 16)")
{
for (int16_t i = -32768; i <= -129; ++i)
for (int16_t i = -32768; i <= int16_t(-129); ++i)
{
CAPTURE(i)

Expand Down
2 changes: 1 addition & 1 deletion test/src/unit-regression1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ using foo_json = nlohmann::basic_json<std::map, std::vector, std::string, bool,

namespace
{
struct nocopy
struct nocopy // NOLINT(cppcoreguidelines-special-member-functions,hicpp-special-member-functions)
{
nocopy() = default;
nocopy(const nocopy&) = delete;
Expand Down
1 change: 1 addition & 0 deletions test/src/unit-regression2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ inline bool operator== (NonDefaultFromJsonStruct const& /*unused*/, NonDefaultFr

enum class for_1647 { one, two };

// NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays): this is a false positive
NLOHMANN_JSON_SERIALIZE_ENUM(for_1647,
{
{for_1647::one, "one"},
Expand Down

0 comments on commit 1101f0e

Please sign in to comment.