Skip to content

Commit 39e2768

Browse files
Use DOCTEST_* compiler macros and suppress pragmas warning (#3550)
Use DOCTEST_* macros in place of predefined compiler macros for compiler detection and version checks. The suppression of warning -Wrange-loop-construct in unit-items.cpp causes GCC<11 to warn about pragmas. Suppressed by adding a version check.
1 parent 87cda1d commit 39e2768

File tree

4 files changed

+7
-5
lines changed

4 files changed

+7
-5
lines changed

tests/src/unit-items.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ using nlohmann::json;
3434

3535
// This test suite uses range for loops where values are copied. This is inefficient in usual code, but required to achieve 100% coverage.
3636
DOCTEST_GCC_SUPPRESS_WARNING_PUSH
37-
DOCTEST_GCC_SUPPRESS_WARNING("-Wrange-loop-construct")
37+
#if DOCTEST_GCC >= DOCTEST_COMPILER(11, 0, 0)
38+
DOCTEST_GCC_SUPPRESS_WARNING("-Wrange-loop-construct")
39+
#endif
3840
DOCTEST_CLANG_SUPPRESS_WARNING_PUSH
3941
DOCTEST_CLANG_SUPPRESS_WARNING("-Wrange-loop-construct")
4042

tests/src/unit-iterators2.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -916,7 +916,7 @@ TEST_CASE("iterators 2")
916916
}
917917

918918
// libstdc++ algorithms don't work with Clang 15 (04/2022)
919-
#if !defined(__clang__) || (defined(__clang__) && defined(__GLIBCXX__))
919+
#if !DOCTEST_CLANG || (DOCTEST_CLANG && defined(__GLIBCXX__))
920920
SECTION("algorithms")
921921
{
922922
SECTION("copy")
@@ -955,7 +955,7 @@ TEST_CASE("iterators 2")
955955

956956
// libstdc++ views don't work with Clang 15 (04/2022)
957957
// libc++ hides limited ranges implementation behind guard macro
958-
#if !(defined(__clang__) && (defined(__GLIBCXX__) || defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)))
958+
#if !(DOCTEST_CLANG && (defined(__GLIBCXX__) || defined(_LIBCPP_HAS_NO_INCOMPLETE_RANGES)))
959959
SECTION("views")
960960
{
961961
SECTION("reverse")

tests/src/unit-regression1.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1520,7 +1520,7 @@ TEST_CASE("regression tests, exceptions dependent")
15201520
/////////////////////////////////////////////////////////////////////
15211521

15221522
// the code below fails with Clang on Windows, so we need to exclude it there
1523-
#if defined(__clang__) && (defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__))
1523+
#if DOCTEST_CLANG && (defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__))
15241524
#else
15251525
template <typename T> class array {};
15261526
template <typename T> class object {};

tests/src/unit-regression2.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,7 @@ TEST_CASE("regression tests 2")
803803
const auto j_path = j.get<nlohmann::detail::std_fs::path>();
804804
CHECK(j_path == text_path);
805805

806-
#if defined(__clang__) || ((defined(__GNUC__) && !defined(__INTEL_COMPILER)) && (__GNUC__ > 8 || (__GNUC__ == 8 && __GNUC_MINOR__ >= 4)))
806+
#if DOCTEST_CLANG || DOCTEST_GCC >= DOCTEST_COMPILER(8, 4, 0)
807807
// only known to work on Clang and GCC >=8.4
808808
CHECK_THROWS_WITH_AS(nlohmann::detail::std_fs::path(json(1)), "[json.exception.type_error.302] type must be string, but is number", json::type_error);
809809
#endif

0 commit comments

Comments
 (0)