Skip to content

Commit

Permalink
🚨 fix Clang-Tidy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
falbrechtskirchinger committed Sep 11, 2022
1 parent 9885153 commit d8526c8
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
4 changes: 2 additions & 2 deletions include/nlohmann/detail/macro_scope.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@

#define NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(Type, ...) \
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__)) } \
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__)) }
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__)) }

/*!
@brief macro
Expand All @@ -409,7 +409,7 @@

#define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Type, ...) \
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__)) } \
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__)) }
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__)) }


// inspired from https://stackoverflow.com/a/26745591
Expand Down
4 changes: 2 additions & 2 deletions single_include/nlohmann/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2748,7 +2748,7 @@ JSON_HEDLEY_DIAGNOSTIC_POP

#define NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(Type, ...) \
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__)) } \
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__)) }
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__)) }

/*!
@brief macro
Expand All @@ -2761,7 +2761,7 @@ JSON_HEDLEY_DIAGNOSTIC_POP

#define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Type, ...) \
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__)) } \
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__)) }
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__)) }


// inspired from https://stackoverflow.com/a/26745591
Expand Down
6 changes: 1 addition & 5 deletions tests/src/unit-assert_macro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,7 @@ TEST_CASE("JSON_ASSERT(x)")
assert_counter = 0;
CHECK(assert_counter == 0);

// Fails on Clang 3.5 with "requires a user-provided default constructor"
#if !DOCTEST_CLANG || DOCTEST_CLANG >= DOCTEST_COMPILER(4, 0, 0)
const
#endif
json::iterator it;
const json::iterator it{};
json j;

// in case assertions do not abort execution, an exception is thrown
Expand Down
14 changes: 11 additions & 3 deletions tests/src/unit-constructor1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ using nlohmann::json;
#include <unordered_set>
#include <valarray>


// Various uses of const fail on Clang 3.5 with "requires a user-provided default constructor"
#if !DOCTEST_CLANG || DOCTEST_CLANG >= DOCTEST_COMPILER(4, 0, 0)
#define CONST const
#else
#define CONST
#endif

TEST_CASE("constructors")
{
SECTION("create an empty value with a given type")
Expand Down Expand Up @@ -124,7 +132,7 @@ TEST_CASE("constructors")
{
SECTION("empty object")
{
json::object_t const o;
json::object_t const o{};
json const j(o);
CHECK(j.type() == json::value_t::object);
}
Expand Down Expand Up @@ -209,7 +217,7 @@ TEST_CASE("constructors")
{
SECTION("empty array")
{
json::array_t const a;
json::array_t const a{};
json const j(a);
CHECK(j.type() == json::value_t::array);
}
Expand Down Expand Up @@ -384,7 +392,7 @@ TEST_CASE("constructors")
{
SECTION("empty string")
{
json::string_t const s;
json::string_t const s{};
json const j(s);
CHECK(j.type() == json::value_t::string);
}
Expand Down

0 comments on commit d8526c8

Please sign in to comment.