diff --git a/src/CppUTest/Utest.cpp b/src/CppUTest/Utest.cpp index 90d3532b0..2d8061e6b 100644 --- a/src/CppUTest/Utest.cpp +++ b/src/CppUTest/Utest.cpp @@ -30,6 +30,10 @@ #include "CppUTest/PlatformSpecificFunctions.h" #include "CppUTest/TestOutput.h" +#if defined(__GNUC__) && __GNUC__ >= 11 +# define NEEDS_DISABLE_NULL_WARNING +#endif /* GCC >= 11 */ + bool doubles_equal(double d1, double d2, double threshold) { if (PlatformSpecificIsNan(d1) || PlatformSpecificIsNan(d2) || PlatformSpecificIsNan(threshold)) @@ -158,10 +162,20 @@ UtestShell::~UtestShell() } // LCOV_EXCL_START - actually covered but not in .gcno due to race condition +#ifdef NEEDS_DISABLE_NULL_WARNING +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wnonnull" +#endif /* NEEDS_DISABLE_NULL_WARNING */ + static void defaultCrashMethod() { - UtestShell* ptr = (UtestShell*) NULLPTR; ptr->countTests(); + UtestShell* ptr = (UtestShell*) NULLPTR; + ptr->countTests(); } + +#ifdef NEEDS_DISABLE_NULL_WARNING +# pragma GCC diagnostic pop +#endif /* NEEDS_DISABLE_NULL_WARNING */ // LCOV_EXCL_STOP static void (*pleaseCrashMeRightNow) () = defaultCrashMethod; diff --git a/tests/CppUTest/MemoryOperatorOverloadTest.cpp b/tests/CppUTest/MemoryOperatorOverloadTest.cpp index 973c46098..5e3b4db22 100644 --- a/tests/CppUTest/MemoryOperatorOverloadTest.cpp +++ b/tests/CppUTest/MemoryOperatorOverloadTest.cpp @@ -10,6 +10,11 @@ #include "CppUTest/TestHarness_c.h" #include "AllocationInCFile.h" +#if defined(__GNUC__) && __GNUC__ >= 11 +# define NEEDS_DISABLE_FREE_NON_HEEP_WARNING +#endif /* GCC >= 11 */ + + TEST_GROUP(BasicBehavior) { }; @@ -60,12 +65,22 @@ TEST(BasicBehavior, DeleteWithSizeParameterWorks) } #endif +#ifdef NEEDS_DISABLE_FREE_NON_HEEP_WARNING +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wfree-nonheap-object" +#endif /* NEEDS_DISABLE_FREE_NON_HEEP_WARNING */ + static void deleteUnallocatedMemory() { delete (char*) 0x1234678; FAIL("Should never come here"); // LCOV_EXCL_LINE } // LCOV_EXCL_LINE +#ifdef NEEDS_DISABLE_FREE_NON_HEEP_WARNING +# pragma GCC diagnostic pop +#endif /* NEEDS_DISABLE_FREE_NON_HEEP_WARNING */ + + TEST(BasicBehavior, deleteWillNotThrowAnExceptionWhenDeletingUnallocatedMemoryButCanStillCauseTestFailures) { /*