fixing the remaining of the pedantic gcc/clang target warnings

pull/1439/head
onqtam 2019-03-31 13:57:44 +03:00
parent 64873fb5b8
commit da5b7833a0
8 changed files with 36 additions and 53 deletions

View File

@ -28,6 +28,7 @@ SOFTWARE.
*/
#include "doctest_compatibility.h"
DOCTEST_GCC_SUPPRESS_WARNING("-Wfloat-equal")
#include <nlohmann/json.hpp>
using nlohmann::json;
@ -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");
}
@ -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)")

View File

@ -28,6 +28,7 @@ SOFTWARE.
*/
#include "doctest_compatibility.h"
DOCTEST_GCC_SUPPRESS_WARNING("-Wfloat-equal")
#define private public
#include <nlohmann/json.hpp>
@ -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
}
}

View File

@ -28,7 +28,6 @@ SOFTWARE.
*/
#include "doctest_compatibility.h"
DOCTEST_GCC_SUPPRESS_WARNING_WITH_PUSH("-Wsign-promo")
#define private public
#include <nlohmann/json.hpp>

View File

@ -28,6 +28,7 @@ SOFTWARE.
*/
#include "doctest_compatibility.h"
DOCTEST_GCC_SUPPRESS_WARNING("-Wfloat-equal")
#include <nlohmann/json.hpp>
using nlohmann::json;
@ -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.

View File

@ -28,6 +28,7 @@ SOFTWARE.
*/
#include "doctest_compatibility.h"
DOCTEST_GCC_SUPPRESS_WARNING("-Wfloat-equal")
#include <nlohmann/json.hpp>
using nlohmann::json;
@ -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*>());

View File

@ -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>
@ -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
@ -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);
@ -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")

View File

@ -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
@ -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
@ -1598,7 +1603,7 @@ namespace detail {
DOCTEST_DELETE_COPIES(ContextScope);
~ContextScope();
~ContextScope() override;
void stringify(std::ostream* s) const override;
};
@ -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_)) = \
@ -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(); \
@ -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); \
} \
@ -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__)
@ -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 {
@ -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))
@ -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;
}

View File

@ -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"
@ -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