Skip to content

Commit

Permalink
fixing the remaining of the pedantic gcc/clang target warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
onqtam committed Mar 31, 2019
1 parent 64873fb commit da5b783
Show file tree
Hide file tree
Showing 8 changed files with 36 additions and 53 deletions.
5 changes: 1 addition & 4 deletions test/src/unit-cbor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ SOFTWARE.
*/

#include "doctest_compatibility.h"
DOCTEST_GCC_SUPPRESS_WARNING("-Wfloat-equal")

#include <nlohmann/json.hpp>
using nlohmann::json;
Expand Down Expand Up @@ -876,9 +877,7 @@ TEST_CASE("CBOR")
{
json j = json::from_cbor(std::vector<uint8_t>({0xf9, 0x7c, 0x00}));
json::number_float_t d = j;
DOCTEST_GCC_SUPPRESS_WARNING_WITH_PUSH("-Wfloat-equal")
CHECK(d == std::numeric_limits<json::number_float_t>::infinity());
DOCTEST_GCC_SUPPRESS_WARNING_POP
CHECK(j.dump() == "null");
}

Expand All @@ -897,9 +896,7 @@ TEST_CASE("CBOR")
{
json j = json::from_cbor(std::vector<uint8_t>({0xf9, 0x3c, 0x00}));
json::number_float_t d = j;
DOCTEST_GCC_SUPPRESS_WARNING_WITH_PUSH("-Wfloat-equal")
CHECK(d == 1);
DOCTEST_GCC_SUPPRESS_WARNING_POP
}

SECTION("-2 (1 10000 0000000000)")
Expand Down
3 changes: 1 addition & 2 deletions test/src/unit-constructor1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ SOFTWARE.
*/

#include "doctest_compatibility.h"
DOCTEST_GCC_SUPPRESS_WARNING("-Wfloat-equal")

#define private public
#include <nlohmann/json.hpp>
Expand Down Expand Up @@ -351,9 +352,7 @@ TEST_CASE("constructors")
CHECK(jva.size() == va.size());
for (size_t i = 0; i < jva.size(); ++i)
{
DOCTEST_GCC_SUPPRESS_WARNING_WITH_PUSH("-Wfloat-equal")
CHECK(va[i] == jva[i]);
DOCTEST_GCC_SUPPRESS_WARNING_POP
}
}

Expand Down
1 change: 0 additions & 1 deletion test/src/unit-conversions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ SOFTWARE.
*/

#include "doctest_compatibility.h"
DOCTEST_GCC_SUPPRESS_WARNING_WITH_PUSH("-Wsign-promo")

#define private public
#include <nlohmann/json.hpp>
Expand Down
3 changes: 1 addition & 2 deletions test/src/unit-readme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ SOFTWARE.
*/

#include "doctest_compatibility.h"
DOCTEST_GCC_SUPPRESS_WARNING("-Wfloat-equal")

#include <nlohmann/json.hpp>
using nlohmann::json;
Expand Down Expand Up @@ -269,9 +270,7 @@ TEST_CASE("README" * doctest::skip())
int i = 42;
json jn = i;
double f = jn;
DOCTEST_GCC_SUPPRESS_WARNING_WITH_PUSH("-Wfloat-equal")
CHECK(f == 42);
DOCTEST_GCC_SUPPRESS_WARNING_POP

// etc.

Expand Down
3 changes: 1 addition & 2 deletions test/src/unit-reference_access.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ SOFTWARE.
*/

#include "doctest_compatibility.h"
DOCTEST_GCC_SUPPRESS_WARNING("-Wfloat-equal")

#include <nlohmann/json.hpp>
using nlohmann::json;
Expand Down Expand Up @@ -287,9 +288,7 @@ TEST_CASE("reference access")
// check if references are returned correctly
test_type& p1 = value.get_ref<test_type&>();
CHECK(&p1 == value.get_ptr<test_type*>());
DOCTEST_GCC_SUPPRESS_WARNING_WITH_PUSH("-Wfloat-equal")
CHECK(p1 == value.get<test_type>());
DOCTEST_GCC_SUPPRESS_WARNING_POP

const test_type& p2 = value.get_ref<const test_type&>();
CHECK(&p2 == value.get_ptr<const test_type*>());
Expand Down
8 changes: 1 addition & 7 deletions test/src/unit-regression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ SOFTWARE.
*/

#include "doctest_compatibility.h"
DOCTEST_GCC_SUPPRESS_WARNING_WITH_PUSH("-Wsign-promo")
DOCTEST_GCC_SUPPRESS_WARNING("-Wfloat-equal")

// for some reason including this after the json header leads to linker errors with VS 2017...
#include <locale>
Expand Down Expand Up @@ -315,9 +315,7 @@ TEST_CASE("regression tests")
// unsigned integer parsing - expected to overflow and be stored as a float
j = custom_json::parse("4294967296"); // 2^32
CHECK(static_cast<int>(j.type()) == static_cast<int>(custom_json::value_t::number_float));
DOCTEST_GCC_SUPPRESS_WARNING_WITH_PUSH("-Wfloat-equal")
CHECK(j.get<float>() == 4294967296.0f);
DOCTEST_GCC_SUPPRESS_WARNING_POP

// integer object creation - expected to wrap and still be stored as an integer
j = -2147483649LL; // -2^31-1
Expand Down Expand Up @@ -482,9 +480,7 @@ TEST_CASE("regression tests")
json j;

j = json::parse("-0.0");
DOCTEST_GCC_SUPPRESS_WARNING_WITH_PUSH("-Wfloat-equal")
CHECK(j.get<double>() == -0.0);
DOCTEST_GCC_SUPPRESS_WARNING_POP

j = json::parse("2.22507385850720113605740979670913197593481954635164564e-308");
CHECK(j.get<double>() == 2.2250738585072009e-308);
Expand Down Expand Up @@ -522,9 +518,7 @@ TEST_CASE("regression tests")
// long double
nlohmann::basic_json<std::map, std::vector, std::string, bool, int64_t, uint64_t, long double>
j_long_double = 1.23e45L;
DOCTEST_GCC_SUPPRESS_WARNING_WITH_PUSH("-Wfloat-equal")
CHECK(j_long_double.get<long double>() == 1.23e45L);
DOCTEST_GCC_SUPPRESS_WARNING_POP
}

SECTION("issue #228 - double values are serialized with commas as decimal points")
Expand Down
42 changes: 30 additions & 12 deletions test/thirdparty/doctest/doctest.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ DOCTEST_GCC_SUPPRESS_WARNING("-Winline")
DOCTEST_GCC_SUPPRESS_WARNING("-Wunused-local-typedefs")
DOCTEST_GCC_SUPPRESS_WARNING("-Wuseless-cast")
DOCTEST_GCC_SUPPRESS_WARNING("-Wnoexcept")
DOCTEST_GCC_SUPPRESS_WARNING("-Wsign-promo")

DOCTEST_MSVC_SUPPRESS_WARNING_PUSH
DOCTEST_MSVC_SUPPRESS_WARNING(4616) // invalid compiler warning
Expand Down Expand Up @@ -994,6 +995,10 @@ namespace detail {
};

DOCTEST_INTERFACE bool checkIfShouldThrow(assertType::Enum at);

#ifndef DOCTEST_CONFIG_NO_EXCEPTIONS
[[noreturn]]
#endif // DOCTEST_CONFIG_NO_EXCEPTIONS
DOCTEST_INTERFACE void throwException();

struct DOCTEST_INTERFACE Subcase
Expand Down Expand Up @@ -1598,7 +1603,7 @@ namespace detail {

DOCTEST_DELETE_COPIES(ContextScope);

~ContextScope();
~ContextScope() override;

void stringify(std::ostream* s) const override;
};
Expand Down Expand Up @@ -1839,6 +1844,15 @@ int registerReporter(const char* name, int priority) {
} catch(...) { _DOCTEST_RB.translateException(); }
#endif // DOCTEST_CONFIG_NO_TRY_CATCH_IN_ASSERTS

#ifdef DOCTEST_CONFIG_VOID_CAST_EXPRESSIONS
#define DOCTEST_CAST_TO_VOID(x) \
DOCTEST_GCC_SUPPRESS_WARNING_WITH_PUSH("-Wuseless-cast") \
static_cast<void>(x); \
DOCTEST_GCC_SUPPRESS_WARNING_POP
#else // DOCTEST_CONFIG_VOID_CAST_EXPRESSIONS
#define DOCTEST_CAST_TO_VOID(x) x;
#endif // DOCTEST_CONFIG_VOID_CAST_EXPRESSIONS

// registers the test by initializing a dummy var with a function
#define DOCTEST_REGISTER_FUNCTION(global_prefix, f, decorators) \
global_prefix DOCTEST_GLOBAL_NO_WARNINGS(DOCTEST_ANONYMOUS(_DOCTEST_ANON_VAR_)) = \
Expand Down Expand Up @@ -2108,15 +2122,13 @@ constexpr T to_lvalue = x;
#define DOCTEST_REQUIRE_FALSE_MESSAGE(cond, msg) do { DOCTEST_INFO(msg); DOCTEST_ASSERT_IMPLEMENT_2(DT_REQUIRE_FALSE, cond); } while((void)0, 0)
// clang-format on

#define DOCTEST_ASSERT_THROWS(expr, assert_type) DOCTEST_ASSERT_THROWS_WITH(expr, assert_type, "")

#define DOCTEST_ASSERT_THROWS_AS(expr, assert_type, ...) \
do { \
if(!doctest::getContextOptions()->no_throw) { \
doctest::detail::ResultBuilder _DOCTEST_RB(doctest::assertType::assert_type, __FILE__, \
__LINE__, #expr, #__VA_ARGS__); \
try { \
expr; \
DOCTEST_CAST_TO_VOID(expr) \
} catch(const doctest::detail::remove_const< \
doctest::detail::remove_reference<__VA_ARGS__>::type>::type&) { \
_DOCTEST_RB.translateException(); \
Expand All @@ -2132,7 +2144,7 @@ constexpr T to_lvalue = x;
doctest::detail::ResultBuilder _DOCTEST_RB(doctest::assertType::assert_type, __FILE__, \
__LINE__, #expr, __VA_ARGS__); \
try { \
expr; \
DOCTEST_CAST_TO_VOID(expr) \
} catch(...) { _DOCTEST_RB.translateException(); } \
DOCTEST_ASSERT_LOG_AND_REACT(_DOCTEST_RB); \
} \
Expand All @@ -2143,15 +2155,15 @@ constexpr T to_lvalue = x;
doctest::detail::ResultBuilder _DOCTEST_RB(doctest::assertType::assert_type, __FILE__, \
__LINE__, #expr); \
try { \
expr; \
DOCTEST_CAST_TO_VOID(expr) \
} catch(...) { _DOCTEST_RB.translateException(); } \
DOCTEST_ASSERT_LOG_AND_REACT(_DOCTEST_RB); \
} while((void)0, 0)

// clang-format off
#define DOCTEST_WARN_THROWS(expr) DOCTEST_ASSERT_THROWS(expr, DT_WARN_THROWS)
#define DOCTEST_CHECK_THROWS(expr) DOCTEST_ASSERT_THROWS(expr, DT_CHECK_THROWS)
#define DOCTEST_REQUIRE_THROWS(expr) DOCTEST_ASSERT_THROWS(expr, DT_REQUIRE_THROWS)
#define DOCTEST_WARN_THROWS(expr) DOCTEST_ASSERT_THROWS_WITH(expr, DT_WARN_THROWS, "")
#define DOCTEST_CHECK_THROWS(expr) DOCTEST_ASSERT_THROWS_WITH(expr, DT_CHECK_THROWS, "")
#define DOCTEST_REQUIRE_THROWS(expr) DOCTEST_ASSERT_THROWS_WITH(expr, DT_REQUIRE_THROWS, "")

#define DOCTEST_WARN_THROWS_AS(expr, ...) DOCTEST_ASSERT_THROWS_AS(expr, DT_WARN_THROWS_AS, __VA_ARGS__)
#define DOCTEST_CHECK_THROWS_AS(expr, ...) DOCTEST_ASSERT_THROWS_AS(expr, DT_CHECK_THROWS_AS, __VA_ARGS__)
Expand Down Expand Up @@ -3504,11 +3516,11 @@ namespace detail {
return false;
}

void throwException() {
#ifndef DOCTEST_CONFIG_NO_EXCEPTIONS
throw TestFailureException();
[[noreturn]] void throwException() { throw TestFailureException(); }
#else // DOCTEST_CONFIG_NO_EXCEPTIONS
void throwException() {}
#endif // DOCTEST_CONFIG_NO_EXCEPTIONS
}
} // namespace detail

namespace {
Expand Down Expand Up @@ -4868,12 +4880,16 @@ namespace {
}

void test_case_exception(const TestCaseException& e) override {
std::lock_guard<std::mutex> lock(mutex);

xml.scopedElement("Exception")
.writeAttribute("crash", e.is_crash)
.writeText(e.error_string.c_str());
}

void subcase_start(const SubcaseSignature& in) override {
std::lock_guard<std::mutex> lock(mutex);

xml.startElement("SubCase")
.writeAttribute("name", in.m_name)
.writeAttribute("filename", skipPathFromFilename(in.m_file))
Expand Down Expand Up @@ -5319,11 +5335,13 @@ namespace {
}

void subcase_start(const SubcaseSignature& subc) override {
std::lock_guard<std::mutex> lock(mutex);
subcasesStack.push_back(subc);
hasLoggedCurrentTestStart = false;
}

void subcase_end() override {
std::lock_guard<std::mutex> lock(mutex);
subcasesStack.pop_back();
hasLoggedCurrentTestStart = false;
}
Expand Down
24 changes: 1 addition & 23 deletions test/thirdparty/doctest/doctest_compatibility.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#ifndef DOCTEST_COMPATIBILITY
#define DOCTEST_COMPATIBILITY

#define DOCTEST_CONFIG_VOID_CAST_EXPRESSIONS
#define DOCTEST_THREAD_LOCAL // enable single-threaded builds on XCode 6/7 - https://github.com/onqtam/doctest/issues/172
#include "doctest.h"

Expand All @@ -25,29 +26,6 @@
#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 da5b783

Please sign in to comment.