From 06cf2a4724d74af88c0a4a9a7445424cc831afd6 Mon Sep 17 00:00:00 2001 From: Alecto Irene Perez Date: Thu, 21 Oct 2021 07:47:21 -0600 Subject: [PATCH] Apply PR #2297 to devel branch (#2300) * Apply PR #2297 to devel branch It turns out that Issue #2272 partially affected the devel branch. When building tests with C++20, the compiler emits a warning that top-level comma expressions in array subscripts are depricated. Warnings are treated as errors, so this caused the build to fail. This commit adds localized warning suppression in accordance with this recommendation here: https://github.com/catchorg/Catch2/pull/2297#discussion_r720848392 Signed-off-by: Alecto Irene Perez * Fixed unknown pragma warning on old versions of gcc & clang This commit fixes an unkwown pragma warning on older versions of GCC and Clang. These older versions don't have a warning for depricated use of the comma subscript. Because warning suppression is localized, and only refers to the comma subscript warning, it doesn't affect compiler warnings in other parts of the code. Signed-off-by: Alecto Irene Perez * More #warning backwards compatibility fixes Signed-off-by: Alecto Irene Perez --- tests/SelfTest/UsageTests/Message.tests.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/SelfTest/UsageTests/Message.tests.cpp b/tests/SelfTest/UsageTests/Message.tests.cpp index a30c2e9e..97ac4abd 100644 --- a/tests/SelfTest/UsageTests/Message.tests.cpp +++ b/tests/SelfTest/UsageTests/Message.tests.cpp @@ -238,6 +238,20 @@ std::ostream& operator<<(std::ostream& out, helper_1436 const& helper) { return out; } +// Clang and gcc have different names for this warning, and clang also +// warns about an unused value. This warning must be disabled for C++20. +#if defined(__GNUG__) && !defined(__clang__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wpragmas" +#pragma GCC diagnostic ignored "-Wcomma-subscript" +#elif defined(__clang__) +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wunknown-pragmas" +#pragma clang diagnostic ignored "-Wunknown-warning-option" +#pragma clang diagnostic ignored "-Wdeprecated-comma-subscript" +#pragma clang diagnostic ignored "-Wunused-value" +#endif + TEST_CASE("CAPTURE can deal with complex expressions involving commas", "[messages][capture]") { CAPTURE(std::vector{1, 2, 3}[0, 1, 2], std::vector{1, 2, 3}[(0, 1)], @@ -248,6 +262,10 @@ TEST_CASE("CAPTURE can deal with complex expressions involving commas", "[messag SUCCEED(); } +#ifdef __GNUG__ +#pragma GCC diagnostic pop +#endif + TEST_CASE("CAPTURE parses string and character constants", "[messages][capture]") { CAPTURE(("comma, in string", "escaped, \", "), "single quote in string,',", "some escapes, \\,\\\\"); CAPTURE("some, ), unmatched, } prenheses {[<");