Skip to content

Commit

Permalink
fixed a bunch of warnings from the Makefile from the root of the repo
Browse files Browse the repository at this point in the history
  • Loading branch information
onqtam committed Mar 26, 2019
1 parent 82af0ec commit 5d511a6
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 16 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ doctest:

# calling Clang with all warnings, except:
# -Wno-documentation-unknown-command: code uses user-defined commands like @complexity
# -Wno-exit-time-destructors: warning in json code triggered by NLOHMANN_JSON_SERIALIZE_ENUM
# -Wno-keyword-macro: unit-tests use "#define private public"
# -Wno-deprecated-declarations: the library deprecated some functions
# -Wno-weak-vtables: exception class is defined inline, but has virtual method
Expand All @@ -130,6 +131,7 @@ pedantic_clang:
-Werror \
-Weverything \
-Wno-documentation-unknown-command \
-Wno-exit-time-destructors \
-Wno-keyword-macro \
-Wno-deprecated-declarations \
-Wno-weak-vtables \
Expand Down
22 changes: 11 additions & 11 deletions test/src/unit-allocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ TEST_CASE("bad_alloc")
bad_allocator>;

// creating an object should throw
CHECK_THROWS_AS(auto tmp = bad_json(bad_json::value_t::object), std::bad_alloc&);
CHECK_THROWS_AS(bad_json(bad_json::value_t::object), std::bad_alloc&);
}
}

Expand Down Expand Up @@ -153,7 +153,7 @@ TEST_CASE("controlled bad_alloc")
auto t = my_json::value_t::object;
CHECK_NOTHROW(my_allocator_clean_up(my_json::json_value(t).object));
next_construct_fails = true;
CHECK_THROWS_AS(auto tmp = my_json::json_value(t), std::bad_alloc&);
CHECK_THROWS_AS(my_json::json_value(t), std::bad_alloc&);
next_construct_fails = false;
}
SECTION("array")
Expand All @@ -162,7 +162,7 @@ TEST_CASE("controlled bad_alloc")
auto t = my_json::value_t::array;
CHECK_NOTHROW(my_allocator_clean_up(my_json::json_value(t).array));
next_construct_fails = true;
CHECK_THROWS_AS(auto tmp = my_json::json_value(t), std::bad_alloc&);
CHECK_THROWS_AS(my_json::json_value(t), std::bad_alloc&);
next_construct_fails = false;
}
SECTION("string")
Expand All @@ -171,7 +171,7 @@ TEST_CASE("controlled bad_alloc")
auto t = my_json::value_t::string;
CHECK_NOTHROW(my_allocator_clean_up(my_json::json_value(t).string));
next_construct_fails = true;
CHECK_THROWS_AS(auto tmp = my_json::json_value(t), std::bad_alloc&);
CHECK_THROWS_AS(my_json::json_value(t), std::bad_alloc&);
next_construct_fails = false;
}
}
Expand All @@ -182,7 +182,7 @@ TEST_CASE("controlled bad_alloc")
my_json::string_t v("foo");
CHECK_NOTHROW(my_allocator_clean_up(my_json::json_value(v).string));
next_construct_fails = true;
CHECK_THROWS_AS(auto tmp = my_json::json_value(v), std::bad_alloc&);
CHECK_THROWS_AS(my_json::json_value(v), std::bad_alloc&);
next_construct_fails = false;
}
}
Expand All @@ -193,19 +193,19 @@ TEST_CASE("controlled bad_alloc")
{
next_construct_fails = false;
std::map<std::string, std::string> v {{"foo", "bar"}};
CHECK_NOTHROW(auto tmp = my_json(v));
CHECK_NOTHROW(my_json(v));
next_construct_fails = true;
CHECK_THROWS_AS(auto tmp = my_json(v), std::bad_alloc&);
CHECK_THROWS_AS(my_json(v), std::bad_alloc&);
next_construct_fails = false;
}

SECTION("basic_json(const CompatibleArrayType&)")
{
next_construct_fails = false;
std::vector<std::string> v {"foo", "bar", "baz"};
CHECK_NOTHROW(auto tmp = my_json(v));
CHECK_NOTHROW(my_json(v));
next_construct_fails = true;
CHECK_THROWS_AS(auto tmp = my_json(v), std::bad_alloc&);
CHECK_THROWS_AS(my_json(v), std::bad_alloc&);
next_construct_fails = false;
}

Expand All @@ -222,9 +222,9 @@ TEST_CASE("controlled bad_alloc")
{
next_construct_fails = false;
std::string s("foo");
CHECK_NOTHROW(auto tmp = my_json(s));
CHECK_NOTHROW(my_json(s));
next_construct_fails = true;
CHECK_THROWS_AS(auto tmp = my_json(s), std::bad_alloc&);
CHECK_THROWS_AS(my_json(s), std::bad_alloc&);
next_construct_fails = false;
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/src/unit-regression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ TEST_CASE("regression tests")
int number = j["Number"];
CHECK(number == 100);
float foo = j["Foo"];
CHECK(foo == Approx(42.42));
CHECK(static_cast<double>(foo) == Approx(42.42));
}

SECTION("issue #89 - nonstandard integer type")
Expand Down
4 changes: 2 additions & 2 deletions test/src/unit-testsuites.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ TEST_CASE("RFC 7159 examples")
}
)";

CHECK_NOTHROW(auto tmp = json(json_contents));
CHECK_NOTHROW(json(json_contents));
}

{
Expand All @@ -484,7 +484,7 @@ TEST_CASE("RFC 7159 examples")
"Country": "US"
}
])";
CHECK_NOTHROW(auto tmp = json(json_contents));
CHECK_NOTHROW(json(json_contents));
}

CHECK(json::parse("\"Hello world!\"") == json("Hello world!"));
Expand Down
11 changes: 9 additions & 2 deletions test/thirdparty/doctest/doctest.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ DOCTEST_GCC_SUPPRESS_WARNING("-Wnon-virtual-dtor")
DOCTEST_GCC_SUPPRESS_WARNING("-Winline")
DOCTEST_GCC_SUPPRESS_WARNING("-Wunused-local-typedefs")
DOCTEST_GCC_SUPPRESS_WARNING("-Wuseless-cast")
DOCTEST_GCC_SUPPRESS_WARNING("-Wnoexcept")

DOCTEST_MSVC_SUPPRESS_WARNING_PUSH
DOCTEST_MSVC_SUPPRESS_WARNING(4616) // invalid compiler warning
Expand Down Expand Up @@ -1599,7 +1600,7 @@ namespace detail {

~ContextScope();

void stringify(std::ostream* s) const;
void stringify(std::ostream* s) const override;
};

struct DOCTEST_INTERFACE MessageBuilder : public MessageData
Expand Down Expand Up @@ -2722,6 +2723,9 @@ DOCTEST_GCC_SUPPRESS_WARNING("-Wold-style-cast")
DOCTEST_GCC_SUPPRESS_WARNING("-Wunused-local-typedefs")
DOCTEST_GCC_SUPPRESS_WARNING("-Wuseless-cast")
DOCTEST_GCC_SUPPRESS_WARNING("-Wunused-function")
DOCTEST_GCC_SUPPRESS_WARNING("-Wmultiple-inheritance")
DOCTEST_GCC_SUPPRESS_WARNING("-Wnoexcept")
DOCTEST_GCC_SUPPRESS_WARNING("-Wsuggest-attribute")

DOCTEST_MSVC_SUPPRESS_WARNING_PUSH
DOCTEST_MSVC_SUPPRESS_WARNING(4616) // invalid compiler warning
Expand Down Expand Up @@ -3836,6 +3840,7 @@ namespace {
if(curr->translate(res))
return res;
// clang-format off
DOCTEST_GCC_SUPPRESS_WARNING_WITH_PUSH("-Wcatch-value")
try {
throw;
} catch(std::exception& ex) {
Expand All @@ -3847,6 +3852,7 @@ namespace {
} catch(...) {
return "unknown exception";
}
DOCTEST_GCC_SUPPRESS_WARNING_POP
// clang-format on
#else // DOCTEST_CONFIG_NO_EXCEPTIONS
return "";
Expand Down Expand Up @@ -4872,6 +4878,7 @@ namespace {
.writeAttribute("name", in.m_name)
.writeAttribute("filename", skipPathFromFilename(in.m_file))
.writeAttribute("line", line(in.m_line));
xml.ensureTagClosed();
}

void subcase_end() override { xml.endElement(); }
Expand Down Expand Up @@ -5997,4 +6004,4 @@ DOCTEST_MSVC_SUPPRESS_WARNING_POP
DOCTEST_GCC_SUPPRESS_WARNING_POP

#endif // DOCTEST_LIBRARY_IMPLEMENTATION
#endif // DOCTEST_CONFIG_IMPLEMENT
#endif // DOCTEST_CONFIG_IMPLEMENT
23 changes: 23 additions & 0 deletions test/thirdparty/doctest/doctest_compatibility.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,29 @@
#define CHECK_THROWS_WITH_STD_STR(expr, str) \
CHECK_THROWS_WITH_STD_STR_IMPL(expr, str, DOCTEST_ANONYMOUS(DOCTEST_STD_STRING_))

#undef CHECK_THROWS
#undef CHECK_THROWS_AS
#undef CHECK_THROWS_WITH
#undef CHECK_NOTHROW

#undef REQUIRE_THROWS
#undef REQUIRE_THROWS_AS
#undef REQUIRE_THROWS_WITH
#undef REQUIRE_NOTHROW

// doctest allows multiple statements in these macros (even blocks of code) but json
// tests rely on passing single function/constructor calls which have a [[nodiscard]]
// attribute so here we static_cast to void - just like Catch does
#define CHECK_THROWS(expr) DOCTEST_CHECK_THROWS(static_cast<void>(expr))
#define CHECK_THROWS_AS(expr, e) DOCTEST_CHECK_THROWS_AS(static_cast<void>(expr), e)
#define CHECK_THROWS_WITH(expr, e) DOCTEST_CHECK_THROWS_WITH(static_cast<void>(expr), e)
#define CHECK_NOTHROW(expr) DOCTEST_CHECK_NOTHROW(static_cast<void>(expr))

#define REQUIRE_THROWS(expr) DOCTEST_REQUIRE_THROWS(static_cast<void>(expr))
#define REQUIRE_THROWS_AS(expr, e) DOCTEST_REQUIRE_THROWS_AS(static_cast<void>(expr), e)
#define REQUIRE_THROWS_WITH(expr, e) DOCTEST_REQUIRE_THROWS_WITH(static_cast<void>(expr), e)
#define REQUIRE_NOTHROW(expr) DOCTEST_REQUIRE_NOTHROW(static_cast<void>(expr))

// included here because for some tests in the json repository private is defined as
// public and if no STL header is included before that then in the json include when STL
// stuff is included the MSVC STL complains (errors) that C++ keywords are being redefined
Expand Down

0 comments on commit 5d511a6

Please sign in to comment.