fixed a bunch of warnings from the Makefile from the root of the repo

pull/1439/head
onqtam 2019-03-27 00:58:53 +02:00
parent 82af0ecdc1
commit 5d511a6e96
6 changed files with 48 additions and 16 deletions

View File

@ -116,6 +116,7 @@ doctest:
# calling Clang with all warnings, except: # calling Clang with all warnings, except:
# -Wno-documentation-unknown-command: code uses user-defined commands like @complexity # -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-keyword-macro: unit-tests use "#define private public"
# -Wno-deprecated-declarations: the library deprecated some functions # -Wno-deprecated-declarations: the library deprecated some functions
# -Wno-weak-vtables: exception class is defined inline, but has virtual method # -Wno-weak-vtables: exception class is defined inline, but has virtual method
@ -130,6 +131,7 @@ pedantic_clang:
-Werror \ -Werror \
-Weverything \ -Weverything \
-Wno-documentation-unknown-command \ -Wno-documentation-unknown-command \
-Wno-exit-time-destructors \
-Wno-keyword-macro \ -Wno-keyword-macro \
-Wno-deprecated-declarations \ -Wno-deprecated-declarations \
-Wno-weak-vtables \ -Wno-weak-vtables \

View File

@ -61,7 +61,7 @@ TEST_CASE("bad_alloc")
bad_allocator>; bad_allocator>;
// creating an object should throw // 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&);
} }
} }
@ -153,7 +153,7 @@ TEST_CASE("controlled bad_alloc")
auto t = my_json::value_t::object; auto t = my_json::value_t::object;
CHECK_NOTHROW(my_allocator_clean_up(my_json::json_value(t).object)); CHECK_NOTHROW(my_allocator_clean_up(my_json::json_value(t).object));
next_construct_fails = true; 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; next_construct_fails = false;
} }
SECTION("array") SECTION("array")
@ -162,7 +162,7 @@ TEST_CASE("controlled bad_alloc")
auto t = my_json::value_t::array; auto t = my_json::value_t::array;
CHECK_NOTHROW(my_allocator_clean_up(my_json::json_value(t).array)); CHECK_NOTHROW(my_allocator_clean_up(my_json::json_value(t).array));
next_construct_fails = true; 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; next_construct_fails = false;
} }
SECTION("string") SECTION("string")
@ -171,7 +171,7 @@ TEST_CASE("controlled bad_alloc")
auto t = my_json::value_t::string; auto t = my_json::value_t::string;
CHECK_NOTHROW(my_allocator_clean_up(my_json::json_value(t).string)); CHECK_NOTHROW(my_allocator_clean_up(my_json::json_value(t).string));
next_construct_fails = true; 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; next_construct_fails = false;
} }
} }
@ -182,7 +182,7 @@ TEST_CASE("controlled bad_alloc")
my_json::string_t v("foo"); my_json::string_t v("foo");
CHECK_NOTHROW(my_allocator_clean_up(my_json::json_value(v).string)); CHECK_NOTHROW(my_allocator_clean_up(my_json::json_value(v).string));
next_construct_fails = true; 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; next_construct_fails = false;
} }
} }
@ -193,9 +193,9 @@ TEST_CASE("controlled bad_alloc")
{ {
next_construct_fails = false; next_construct_fails = false;
std::map<std::string, std::string> v {{"foo", "bar"}}; 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; 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; next_construct_fails = false;
} }
@ -203,9 +203,9 @@ TEST_CASE("controlled bad_alloc")
{ {
next_construct_fails = false; next_construct_fails = false;
std::vector<std::string> v {"foo", "bar", "baz"}; std::vector<std::string> v {"foo", "bar", "baz"};
CHECK_NOTHROW(auto tmp = my_json(v)); CHECK_NOTHROW(my_json(v));
next_construct_fails = true; 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; next_construct_fails = false;
} }
@ -222,9 +222,9 @@ TEST_CASE("controlled bad_alloc")
{ {
next_construct_fails = false; next_construct_fails = false;
std::string s("foo"); std::string s("foo");
CHECK_NOTHROW(auto tmp = my_json(s)); CHECK_NOTHROW(my_json(s));
next_construct_fails = true; 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; next_construct_fails = false;
} }
} }

View File

@ -292,7 +292,7 @@ TEST_CASE("regression tests")
int number = j["Number"]; int number = j["Number"];
CHECK(number == 100); CHECK(number == 100);
float foo = j["Foo"]; float foo = j["Foo"];
CHECK(foo == Approx(42.42)); CHECK(static_cast<double>(foo) == Approx(42.42));
} }
SECTION("issue #89 - nonstandard integer type") SECTION("issue #89 - nonstandard integer type")

View File

@ -457,7 +457,7 @@ TEST_CASE("RFC 7159 examples")
} }
)"; )";
CHECK_NOTHROW(auto tmp = json(json_contents)); CHECK_NOTHROW(json(json_contents));
} }
{ {
@ -484,7 +484,7 @@ TEST_CASE("RFC 7159 examples")
"Country": "US" "Country": "US"
} }
])"; ])";
CHECK_NOTHROW(auto tmp = json(json_contents)); CHECK_NOTHROW(json(json_contents));
} }
CHECK(json::parse("\"Hello world!\"") == json("Hello world!")); CHECK(json::parse("\"Hello world!\"") == json("Hello world!"));

View File

@ -160,6 +160,7 @@ DOCTEST_GCC_SUPPRESS_WARNING("-Wnon-virtual-dtor")
DOCTEST_GCC_SUPPRESS_WARNING("-Winline") DOCTEST_GCC_SUPPRESS_WARNING("-Winline")
DOCTEST_GCC_SUPPRESS_WARNING("-Wunused-local-typedefs") DOCTEST_GCC_SUPPRESS_WARNING("-Wunused-local-typedefs")
DOCTEST_GCC_SUPPRESS_WARNING("-Wuseless-cast") DOCTEST_GCC_SUPPRESS_WARNING("-Wuseless-cast")
DOCTEST_GCC_SUPPRESS_WARNING("-Wnoexcept")
DOCTEST_MSVC_SUPPRESS_WARNING_PUSH DOCTEST_MSVC_SUPPRESS_WARNING_PUSH
DOCTEST_MSVC_SUPPRESS_WARNING(4616) // invalid compiler warning DOCTEST_MSVC_SUPPRESS_WARNING(4616) // invalid compiler warning
@ -1599,7 +1600,7 @@ namespace detail {
~ContextScope(); ~ContextScope();
void stringify(std::ostream* s) const; void stringify(std::ostream* s) const override;
}; };
struct DOCTEST_INTERFACE MessageBuilder : public MessageData struct DOCTEST_INTERFACE MessageBuilder : public MessageData
@ -2722,6 +2723,9 @@ DOCTEST_GCC_SUPPRESS_WARNING("-Wold-style-cast")
DOCTEST_GCC_SUPPRESS_WARNING("-Wunused-local-typedefs") DOCTEST_GCC_SUPPRESS_WARNING("-Wunused-local-typedefs")
DOCTEST_GCC_SUPPRESS_WARNING("-Wuseless-cast") DOCTEST_GCC_SUPPRESS_WARNING("-Wuseless-cast")
DOCTEST_GCC_SUPPRESS_WARNING("-Wunused-function") 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_PUSH
DOCTEST_MSVC_SUPPRESS_WARNING(4616) // invalid compiler warning DOCTEST_MSVC_SUPPRESS_WARNING(4616) // invalid compiler warning
@ -3836,6 +3840,7 @@ namespace {
if(curr->translate(res)) if(curr->translate(res))
return res; return res;
// clang-format off // clang-format off
DOCTEST_GCC_SUPPRESS_WARNING_WITH_PUSH("-Wcatch-value")
try { try {
throw; throw;
} catch(std::exception& ex) { } catch(std::exception& ex) {
@ -3847,6 +3852,7 @@ namespace {
} catch(...) { } catch(...) {
return "unknown exception"; return "unknown exception";
} }
DOCTEST_GCC_SUPPRESS_WARNING_POP
// clang-format on // clang-format on
#else // DOCTEST_CONFIG_NO_EXCEPTIONS #else // DOCTEST_CONFIG_NO_EXCEPTIONS
return ""; return "";
@ -4872,6 +4878,7 @@ namespace {
.writeAttribute("name", in.m_name) .writeAttribute("name", in.m_name)
.writeAttribute("filename", skipPathFromFilename(in.m_file)) .writeAttribute("filename", skipPathFromFilename(in.m_file))
.writeAttribute("line", line(in.m_line)); .writeAttribute("line", line(in.m_line));
xml.ensureTagClosed();
} }
void subcase_end() override { xml.endElement(); } void subcase_end() override { xml.endElement(); }
@ -5997,4 +6004,4 @@ DOCTEST_MSVC_SUPPRESS_WARNING_POP
DOCTEST_GCC_SUPPRESS_WARNING_POP DOCTEST_GCC_SUPPRESS_WARNING_POP
#endif // DOCTEST_LIBRARY_IMPLEMENTATION #endif // DOCTEST_LIBRARY_IMPLEMENTATION
#endif // DOCTEST_CONFIG_IMPLEMENT #endif // DOCTEST_CONFIG_IMPLEMENT

View File

@ -25,6 +25,29 @@
#define CHECK_THROWS_WITH_STD_STR(expr, str) \ #define CHECK_THROWS_WITH_STD_STR(expr, str) \
CHECK_THROWS_WITH_STD_STR_IMPL(expr, str, DOCTEST_ANONYMOUS(DOCTEST_STD_STRING_)) 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 // 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 // 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 // stuff is included the MSVC STL complains (errors) that C++ keywords are being redefined