From a0e19c25a056ac80028c74f33687ce7ee9d0c09d Mon Sep 17 00:00:00 2001 From: FranckRJ Date: Sun, 14 Apr 2024 17:05:17 +0200 Subject: [PATCH] Fix remaining warnings on GCC / Clang with default options on recent C++ versions. --- tests/default_behaviore_tests.cpp | 13 +------------ tests/move_only_return_tests.cpp | 4 ++-- tests/remove_const_volatile_tests.cpp | 4 ++++ tests/rvalue_arguments_tests.cpp | 7 +++++++ tests/type_info_tests.cpp | 3 ++- tests/verification_tests.cpp | 8 ++++---- 6 files changed, 20 insertions(+), 19 deletions(-) diff --git a/tests/default_behaviore_tests.cpp b/tests/default_behaviore_tests.cpp index 6d1d7cf1..4f8f7652 100644 --- a/tests/default_behaviore_tests.cpp +++ b/tests/default_behaviore_tests.cpp @@ -210,24 +210,13 @@ struct DefaultBehavioreTests : tpunit::TestFixture { public: virtual ~ISomeInterface3() { int a = 0; + (void)a; a++; } virtual void methodWithSomeSharedPointer(std::shared_ptr listener) = 0; }; -// void production_shared_ptr_mock_used_in_invocation() { -// std::shared_ptr pMockInstance; -// Mock mock; -// fakeit::Fake(Dtor(mock)); -// fakeit::Fake(Method(mock, methodWithSomeSharedPointer)); -// -// pMockInstance = mock.getShared(); -// pMockInstance->methodWithSomeSharedPointer(pMockInstance); -// -// pMockInstance = nullptr; -// } - void production_shared_ptr_mock_used_in_invocation() { Mock mock; std::shared_ptr pMockInstance(&mock.get()); diff --git a/tests/move_only_return_tests.cpp b/tests/move_only_return_tests.cpp index ad40e93b..dbc4461b 100644 --- a/tests/move_only_return_tests.cpp +++ b/tests/move_only_return_tests.cpp @@ -18,10 +18,11 @@ struct MoveOnlyReturnTests: tpunit::TestFixture { class AbstractType { public: + virtual ~AbstractType() = default; virtual void foo() = 0; }; - class ConcreteType: public AbstractType { + class ConcreteType : public AbstractType { public: int state; ConcreteType(int value) : @@ -84,4 +85,3 @@ struct MoveOnlyReturnTests: tpunit::TestFixture { ASSERT_EQUAL(ConcreteType(10), i.returnMoveOnlyConcreteTypeByRef()); } } __MoveOnlyReturnTests; - diff --git a/tests/remove_const_volatile_tests.cpp b/tests/remove_const_volatile_tests.cpp index 4c4f3344..e9818d91 100644 --- a/tests/remove_const_volatile_tests.cpp +++ b/tests/remove_const_volatile_tests.cpp @@ -82,7 +82,11 @@ struct RemoveConstVolatileTests : tpunit::TestFixture { } struct ConstVolatileParameters{ +#if FAKEIT_CPLUSPLUS >= 202002L + virtual int func1(const int a, const std::string s) = 0; +#else virtual int func1(const int a, const volatile std::string s) = 0; +#endif }; void TestConstParameters() diff --git a/tests/rvalue_arguments_tests.cpp b/tests/rvalue_arguments_tests.cpp index 74d50039..bcdf3452 100644 --- a/tests/rvalue_arguments_tests.cpp +++ b/tests/rvalue_arguments_tests.cpp @@ -28,6 +28,10 @@ struct RValueTypesTests : tpunit::TestFixture { using CompositeType = std::pair < int, int > ; +#if defined(__GNUG__) && !defined(__clang__) && __GNUC__ >= 13 +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Woverloaded-virtual" +#endif struct RValueInterface { virtual int intRValueArg(int&&) = 0; virtual int compositeRValueArg(CompositeType&&) = 0; @@ -36,6 +40,9 @@ struct RValueTypesTests : tpunit::TestFixture { virtual RValueInterface& operator=(RValueInterface&&) = 0; virtual RValueInterface& operator=(const RValueInterface&) = 0; }; +#if defined(__GNUG__) && !defined(__clang__) && __GNUC__ >= 13 +#pragma GCC diagnostic pop +#endif RValueTypesTests() : TestFixture( diff --git a/tests/type_info_tests.cpp b/tests/type_info_tests.cpp index 373f8c6f..c06b071b 100644 --- a/tests/type_info_tests.cpp +++ b/tests/type_info_tests.cpp @@ -33,7 +33,8 @@ struct TypeInfoTests : tpunit::TestFixture { void mock_should_use_same_typeid_as_mocked_class() { Mock mock; - ASSERT_EQUAL(typeid(mock.get()), typeid(SomeInterface)); + auto& mockRef = mock.get(); + ASSERT_EQUAL(typeid(mockRef), typeid(SomeInterface)); } struct ConcreteType { diff --git a/tests/verification_tests.cpp b/tests/verification_tests.cpp index 5bd7a0be..0388909b 100644 --- a/tests/verification_tests.cpp +++ b/tests/verification_tests.cpp @@ -391,8 +391,8 @@ struct BasicVerification: tpunit::TestFixture { { try { const auto a = VerifyNoOtherInvocations(Method(mock,func)); - if (&a == &a) // use a to avoid unused variable compilation warning. - throw std::runtime_error("some exception"); + (void)a; // use a to avoid unused variable compilation warning. + throw std::runtime_error("some exception"); } catch (std::runtime_error &) { } } @@ -405,8 +405,8 @@ struct BasicVerification: tpunit::TestFixture { try { const auto a = Verify(Method(mock,func)); //const auto b = Verify(Method(mock, func)).Exactly(1); - if (&a == &a) // use a to avoid unused variable compilation warning. - throw std::runtime_error("some exception"); + (void)a; // use a to avoid unused variable compilation warning. + throw std::runtime_error("some exception"); } catch (std::runtime_error &) { } }