From 4fb7039fda3f6588c7ca9664176f8c9e0a023b4a Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Mon, 30 Jan 2023 13:44:59 -0800 Subject: Use GTEST_DISABLE_MSC_WARNINGS macros to disable warnings Prior to this change we had a mixture of pragmas and GTEST_DISABLE_MSC_WARNINGS; this change consolidates all instances to use the macros. PiperOrigin-RevId: 505786926 Change-Id: I2be8f6304387393995081af42ed32c2ad1bba5a7 --- googlemock/include/gmock/gmock-actions.h | 9 ++------ googlemock/include/gmock/gmock-more-actions.h | 9 ++------ googlemock/include/gmock/gmock-more-matchers.h | 14 +++++------ .../include/gmock/internal/gmock-internal-utils.h | 10 ++------ googlemock/src/gmock-spec-builders.cc | 13 ++++------- googlemock/test/gmock-actions_test.cc | 27 +++++++++++----------- googlemock/test/gmock-function-mocker_test.cc | 20 ++++++---------- googlemock/test/gmock-matchers-arithmetic_test.cc | 16 ++++--------- googlemock/test/gmock-matchers-comparisons_test.cc | 17 +++++--------- googlemock/test/gmock-matchers-containers_test.cc | 12 ++++------ googlemock/test/gmock-matchers-misc_test.cc | 12 ++++------ googlemock/test/gmock-more-actions_test.cc | 16 +++++-------- googlemock/test/gmock-spec-builders_test.cc | 9 ++------ googlemock/test/gmock_link_test.h | 9 ++------ googlemock/test/gmock_output_test_.cc | 9 ++------ googletest/include/gtest/gtest.h | 10 ++------ .../include/gtest/internal/gtest-param-util.h | 9 ++------ 17 files changed, 72 insertions(+), 149 deletions(-) diff --git a/googlemock/include/gmock/gmock-actions.h b/googlemock/include/gmock/gmock-actions.h index a6c2489..1cffde2 100644 --- a/googlemock/include/gmock/gmock-actions.h +++ b/googlemock/include/gmock/gmock-actions.h @@ -146,10 +146,7 @@ #include "gmock/internal/gmock-port.h" #include "gmock/internal/gmock-pp.h" -#ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable : 4100) -#endif +GTEST_DISABLE_MSC_WARNINGS_PUSH_(4100) namespace testing { @@ -2295,8 +2292,6 @@ template } // namespace testing -#ifdef _MSC_VER -#pragma warning(pop) -#endif +GTEST_DISABLE_MSC_WARNINGS_POP_() // 4100 #endif // GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_ diff --git a/googlemock/include/gmock/gmock-more-actions.h b/googlemock/include/gmock/gmock-more-actions.h index 78169b1..4030076 100644 --- a/googlemock/include/gmock/gmock-more-actions.h +++ b/googlemock/include/gmock/gmock-more-actions.h @@ -583,10 +583,7 @@ namespace testing { // the macro definition, as the warnings are generated when the macro // is expanded and macro expansion cannot contain #pragma. Therefore // we suppress them here. -#ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable : 4100) -#endif +GTEST_DISABLE_MSC_WARNINGS_PUSH_(4100) namespace internal { @@ -654,9 +651,7 @@ InvokeArgument(Params &&...params) { internal::FlatTupleConstructTag{}, std::forward(params)...)}; } -#ifdef _MSC_VER -#pragma warning(pop) -#endif +GTEST_DISABLE_MSC_WARNINGS_POP_() // 4100 } // namespace testing diff --git a/googlemock/include/gmock/gmock-more-matchers.h b/googlemock/include/gmock/gmock-more-matchers.h index d9a9210..54ea68b 100644 --- a/googlemock/include/gmock/gmock-more-matchers.h +++ b/googlemock/include/gmock/gmock-more-matchers.h @@ -49,14 +49,11 @@ namespace testing { // Silence C4100 (unreferenced formal // parameter) for MSVC -#ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable : 4100) -#if (_MSC_VER == 1900) +GTEST_DISABLE_MSC_WARNINGS_PUSH_(4100) +#if defined(_MSC_VER) && (_MSC_VER == 1900) // and silence C4800 (C4800: 'int *const ': forcing value // to bool 'true' or 'false') for MSVC 14 -#pragma warning(disable : 4800) -#endif +GTEST_DISABLE_MSC_WARNINGS_PUSH_(4800) #endif namespace internal { @@ -113,9 +110,10 @@ MATCHER(IsFalse, negation ? "is true" : "is false") { return !static_cast(arg); } -#ifdef _MSC_VER -#pragma warning(pop) +#if defined(_MSC_VER) && (_MSC_VER == 1900) +GTEST_DISABLE_MSC_WARNINGS_POP_() // 4800 #endif +GTEST_DISABLE_MSC_WARNINGS_POP_() // 4100 } // namespace testing diff --git a/googlemock/include/gmock/internal/gmock-internal-utils.h b/googlemock/include/gmock/internal/gmock-internal-utils.h index 36ab8e2..afbdce0 100644 --- a/googlemock/include/gmock/internal/gmock-internal-utils.h +++ b/googlemock/include/gmock/internal/gmock-internal-utils.h @@ -58,11 +58,7 @@ namespace internal { // Silence MSVC C4100 (unreferenced formal parameter) and // C4805('==': unsafe mix of type 'const int' and type 'const bool') -#ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable : 4100) -#pragma warning(disable : 4805) -#endif +GTEST_DISABLE_MSC_WARNINGS_PUSH_(4100 4805) // Joins a vector of strings as if they are fields of a tuple; returns // the joined string. @@ -480,9 +476,7 @@ using TupleElement = typename std::tuple_element::type; bool Base64Unescape(const std::string& encoded, std::string* decoded); -#ifdef _MSC_VER -#pragma warning(pop) -#endif +GTEST_DISABLE_MSC_WARNINGS_POP_() // 4100 4805 } // namespace internal } // namespace testing diff --git a/googlemock/src/gmock-spec-builders.cc b/googlemock/src/gmock-spec-builders.cc index ea821f8..7d7c55a 100644 --- a/googlemock/src/gmock-spec-builders.cc +++ b/googlemock/src/gmock-spec-builders.cc @@ -57,11 +57,8 @@ // Silence C4800 (C4800: 'int *const ': forcing value // to bool 'true' or 'false') for MSVC 15 -#ifdef _MSC_VER -#if _MSC_VER == 1900 -#pragma warning(push) -#pragma warning(disable : 4800) -#endif +#if defined(_MSC_VER) && (_MSC_VER == 1900) +GTEST_DISABLE_MSC_WARNINGS_PUSH_(4800) #endif namespace testing { @@ -788,8 +785,6 @@ InSequence::~InSequence() { } // namespace testing -#ifdef _MSC_VER -#if _MSC_VER == 1900 -#pragma warning(pop) -#endif +#if defined(_MSC_VER) && (_MSC_VER == 1900) +GTEST_DISABLE_MSC_WARNINGS_POP_() // 4800 #endif diff --git a/googlemock/test/gmock-actions_test.cc b/googlemock/test/gmock-actions_test.cc index 295470e..f2d3042 100644 --- a/googlemock/test/gmock-actions_test.cc +++ b/googlemock/test/gmock-actions_test.cc @@ -31,19 +31,6 @@ // // This file tests the built-in actions. -// Silence C4100 (unreferenced formal parameter) and C4503 (decorated name -// length exceeded) for MSVC. -#ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable : 4100) -#pragma warning(disable : 4503) -#if _MSC_VER == 1900 -// and silence C4800 (C4800: 'int *const ': forcing value -// to bool 'true' or 'false') for MSVC 15 -#pragma warning(disable : 4800) -#endif -#endif - #include "gmock/gmock-actions.h" #include @@ -59,6 +46,15 @@ #include "gtest/gtest-spi.h" #include "gtest/gtest.h" +// Silence C4100 (unreferenced formal parameter) and C4503 (decorated name +// length exceeded) for MSVC. +GTEST_DISABLE_MSC_WARNINGS_PUSH_(4100 4503) +#if defined(_MSC_VER) && (_MSC_VER == 1900) +// and silence C4800 (C4800: 'int *const ': forcing value +// to bool 'true' or 'false') for MSVC 15 +GTEST_DISABLE_MSC_WARNINGS_PUSH_(4800) +#endif + namespace testing { namespace { @@ -2165,3 +2161,8 @@ TEST(ActionMacro, LargeArity) { } // namespace } // namespace testing + +#if defined(_MSC_VER) && (_MSC_VER == 1900) +GTEST_DISABLE_MSC_WARNINGS_POP_() // 4800 +#endif +GTEST_DISABLE_MSC_WARNINGS_POP_() // 4100 4503 diff --git a/googlemock/test/gmock-function-mocker_test.cc b/googlemock/test/gmock-function-mocker_test.cc index 1d15a29..e211aff 100644 --- a/googlemock/test/gmock-function-mocker_test.cc +++ b/googlemock/test/gmock-function-mocker_test.cc @@ -27,17 +27,14 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -// Silence C4503 (decorated name length exceeded) for MSVC. -#ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable : 4503) -#endif - // Google Mock - a framework for writing C++ mock classes. // // This file tests the function mocker classes. #include "gmock/gmock-function-mocker.h" +// Silence C4503 (decorated name length exceeded) for MSVC. +GTEST_DISABLE_MSC_WARNINGS_PUSH_(4503) + #if GTEST_OS_WINDOWS // MSDN says the header file to be included for STDMETHOD is BaseTyps.h but // we are getting compiler errors if we use basetyps.h, hence including @@ -137,10 +134,7 @@ class FooInterface { // significant in determining whether two virtual functions had the same // signature. This was fixed in Visual Studio 2008. However, the compiler // still emits a warning that alerts about this change in behavior. -#ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable : 4373) -#endif +GTEST_DISABLE_MSC_WARNINGS_PUSH_(4373) class MockFoo : public FooInterface { public: MockFoo() {} @@ -285,9 +279,7 @@ class LegacyMockFoo : public FooInterface { LegacyMockFoo& operator=(const LegacyMockFoo&) = delete; }; -#ifdef _MSC_VER -#pragma warning(pop) -#endif +GTEST_DISABLE_MSC_WARNINGS_POP_() // 4373 template class FunctionMockerTest : public testing::Test { @@ -1002,3 +994,5 @@ TEST(MockMethodMockFunctionTest, NoexceptSpecifierPreserved) { } // namespace gmock_function_mocker_test } // namespace testing + +GTEST_DISABLE_MSC_WARNINGS_POP_() // 4503 diff --git a/googlemock/test/gmock-matchers-arithmetic_test.cc b/googlemock/test/gmock-matchers-arithmetic_test.cc index 36c2bf0..fd81a9e 100644 --- a/googlemock/test/gmock-matchers-arithmetic_test.cc +++ b/googlemock/test/gmock-matchers-arithmetic_test.cc @@ -31,18 +31,14 @@ // // This file tests some commonly used argument matchers. -// Silence warning C4244: 'initializing': conversion from 'int' to 'short', -// possible loss of data and C4100, unreferenced local parameter -#ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable : 4244) -#pragma warning(disable : 4100) -#endif - #include "test/gmock-matchers_test.h" #include +// Silence warning C4244: 'initializing': conversion from 'int' to 'short', +// possible loss of data and C4100, unreferenced local parameter +GTEST_DISABLE_MSC_WARNINGS_PUSH_(4244 4100) + namespace testing { namespace gmock_matchers_test { namespace { @@ -1514,6 +1510,4 @@ TEST(AnyOfTest, WorksOnMoveOnlyType) { } // namespace gmock_matchers_test } // namespace testing -#ifdef _MSC_VER -#pragma warning(pop) -#endif +GTEST_DISABLE_MSC_WARNINGS_POP_() // 4244 4100 diff --git a/googlemock/test/gmock-matchers-comparisons_test.cc b/googlemock/test/gmock-matchers-comparisons_test.cc index 83242d6..3db9746 100644 --- a/googlemock/test/gmock-matchers-comparisons_test.cc +++ b/googlemock/test/gmock-matchers-comparisons_test.cc @@ -31,18 +31,15 @@ // // This file tests some commonly used argument matchers. -// Silence warning C4244: 'initializing': conversion from 'int' to 'short', -// possible loss of data and C4100, unreferenced local parameter -#ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable : 4244) -#pragma warning(disable : 4100) -#endif - #include #include "test/gmock-matchers_test.h" +// Silence warning C4244: 'initializing': conversion from 'int' to 'short', +// possible loss of data and C4100, unreferenced local parameter +GTEST_DISABLE_MSC_WARNINGS_PUSH_(4244 4100) + + namespace testing { namespace gmock_matchers_test { namespace { @@ -2354,6 +2351,4 @@ TEST(PolymorphicMatcherTest, CanAccessImpl) { } // namespace gmock_matchers_test } // namespace testing -#ifdef _MSC_VER -#pragma warning(pop) -#endif +GTEST_DISABLE_MSC_WARNINGS_POP_() // 4244 4100 diff --git a/googlemock/test/gmock-matchers-containers_test.cc b/googlemock/test/gmock-matchers-containers_test.cc index 98787f2..b40a26a 100644 --- a/googlemock/test/gmock-matchers-containers_test.cc +++ b/googlemock/test/gmock-matchers-containers_test.cc @@ -31,13 +31,11 @@ // // This file tests some commonly used argument matchers. +#include "gtest/gtest.h" + // Silence warning C4244: 'initializing': conversion from 'int' to 'short', // possible loss of data and C4100, unreferenced local parameter -#ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable : 4244) -#pragma warning(disable : 4100) -#endif +GTEST_DISABLE_MSC_WARNINGS_PUSH_(4244 4100) #include "test/gmock-matchers_test.h" @@ -3124,6 +3122,4 @@ TEST(ContainsTest, WorksForTwoDimensionalNativeArray) { } // namespace gmock_matchers_test } // namespace testing -#ifdef _MSC_VER -#pragma warning(pop) -#endif +GTEST_DISABLE_MSC_WARNINGS_POP_() // 4244 4100 diff --git a/googlemock/test/gmock-matchers-misc_test.cc b/googlemock/test/gmock-matchers-misc_test.cc index 1d1bfb9..c1e4f35 100644 --- a/googlemock/test/gmock-matchers-misc_test.cc +++ b/googlemock/test/gmock-matchers-misc_test.cc @@ -31,13 +31,11 @@ // // This file tests some commonly used argument matchers. +#include "gtest/gtest.h" + // Silence warning C4244: 'initializing': conversion from 'int' to 'short', // possible loss of data and C4100, unreferenced local parameter -#ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable : 4244) -#pragma warning(disable : 4100) -#endif +GTEST_DISABLE_MSC_WARNINGS_PUSH_(4244 4100) #include "test/gmock-matchers_test.h" @@ -1814,6 +1812,4 @@ TEST(ThrowsPredicateCompilesTest, MessageMatcherAcceptsNonMatcher) { } // namespace gmock_matchers_test } // namespace testing -#ifdef _MSC_VER -#pragma warning(pop) -#endif +GTEST_DISABLE_MSC_WARNINGS_POP_() // 4244 4100 diff --git a/googlemock/test/gmock-more-actions_test.cc b/googlemock/test/gmock-more-actions_test.cc index b9b66bf..866e1ab 100644 --- a/googlemock/test/gmock-more-actions_test.cc +++ b/googlemock/test/gmock-more-actions_test.cc @@ -31,11 +31,6 @@ // // This file tests the built-in actions in gmock-actions.h. -#ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable : 4577) -#endif - #include "gmock/gmock-more-actions.h" #include @@ -47,6 +42,8 @@ #include "gtest/gtest-spi.h" #include "gtest/gtest.h" +GTEST_DISABLE_MSC_WARNINGS_PUSH_(4577) + namespace testing { namespace gmock_more_actions_test { @@ -982,11 +979,7 @@ TEST(DoAllTest, ImplicitlyConvertsActionArguments) { // is expanded and macro expansion cannot contain #pragma. Therefore // we suppress them here. // Also suppress C4503 decorated name length exceeded, name was truncated -#ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable : 4100) -#pragma warning(disable : 4503) -#endif +GTEST_DISABLE_MSC_WARNINGS_PUSH_(4100 4503) // Tests the ACTION*() macro family. // Tests that ACTION() can define an action that doesn't reference the @@ -1548,3 +1541,6 @@ TEST(ActionTemplateTest, CanBeOverloadedOnNumberOfValueParameters) { } // namespace gmock_more_actions_test } // namespace testing + +GTEST_DISABLE_MSC_WARNINGS_POP_() // 4100 4503 +GTEST_DISABLE_MSC_WARNINGS_POP_() // 4577 diff --git a/googlemock/test/gmock-spec-builders_test.cc b/googlemock/test/gmock-spec-builders_test.cc index 165944e..6c5e398 100644 --- a/googlemock/test/gmock-spec-builders_test.cc +++ b/googlemock/test/gmock-spec-builders_test.cc @@ -1779,16 +1779,11 @@ TEST(DeletingMockEarlyTest, Success2) { // Suppresses warning on unreferenced formal parameter in MSVC with // -W4. -#ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable : 4100) -#endif +GTEST_DISABLE_MSC_WARNINGS_PUSH_(4100) ACTION_P(Delete, ptr) { delete ptr; } -#ifdef _MSC_VER -#pragma warning(pop) -#endif +GTEST_DISABLE_MSC_WARNINGS_POP_() // 4100 TEST(DeletingMockEarlyTest, CanDeleteSelfInActionReturningVoid) { MockA* const a = new MockA; diff --git a/googlemock/test/gmock_link_test.h b/googlemock/test/gmock_link_test.h index eaf18e9..95a8cb8 100644 --- a/googlemock/test/gmock_link_test.h +++ b/googlemock/test/gmock_link_test.h @@ -423,10 +423,7 @@ TEST(LinkTest, TestThrow) { // the macro definition, as the warnings are generated when the macro // is expanded and macro expansion cannot contain #pragma. Therefore // we suppress them here. -#ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable : 4100) -#endif +GTEST_DISABLE_MSC_WARNINGS_PUSH_(4100) // Tests the linkage of actions created using ACTION macro. namespace { @@ -459,9 +456,7 @@ ACTION_P2(ReturnEqualsEitherOf, first, second) { } } // namespace -#ifdef _MSC_VER -#pragma warning(pop) -#endif +GTEST_DISABLE_MSC_WARNINGS_POP_() // 4100 TEST(LinkTest, TestActionP2Macro) { Mock mock; diff --git a/googlemock/test/gmock_output_test_.cc b/googlemock/test/gmock_output_test_.cc index a178691..af4eaa9 100644 --- a/googlemock/test/gmock_output_test_.cc +++ b/googlemock/test/gmock_output_test_.cc @@ -38,10 +38,7 @@ #include "gtest/gtest.h" // Silence C4100 (unreferenced formal parameter) -#ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable : 4100) -#endif +GTEST_DISABLE_MSC_WARNINGS_PUSH_(4100) using testing::_; using testing::AnyNumber; @@ -286,6 +283,4 @@ int main(int argc, char** argv) { return RUN_ALL_TESTS(); } -#ifdef _MSC_VER -#pragma warning(pop) -#endif +GTEST_DISABLE_MSC_WARNINGS_POP_() // 4100 diff --git a/googletest/include/gtest/gtest.h b/googletest/include/gtest/gtest.h index c4e01ad..f99df35 100644 --- a/googletest/include/gtest/gtest.h +++ b/googletest/include/gtest/gtest.h @@ -166,11 +166,7 @@ namespace testing { // Silence C4100 (unreferenced formal parameter) and 4805 // unsafe mix of type 'const int' and type 'const bool' -#ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable : 4805) -#pragma warning(disable : 4100) -#endif +GTEST_DISABLE_MSC_WARNINGS_PUSH_(4805 4100) // The upper limit for valid stack trace depths. const int kMaxStackTraceDepth = 100; @@ -2214,9 +2210,7 @@ GTEST_API_ std::string TempDir(); // in it should be considered read-only. GTEST_API_ std::string SrcDir(); -#ifdef _MSC_VER -#pragma warning(pop) -#endif +GTEST_DISABLE_MSC_WARNINGS_POP_() // 4805 4100 // Dynamically registers a test with the framework. // diff --git a/googletest/include/gtest/internal/gtest-param-util.h b/googletest/include/gtest/internal/gtest-param-util.h index 358ef72..50435f5 100644 --- a/googletest/include/gtest/internal/gtest-param-util.h +++ b/googletest/include/gtest/internal/gtest-param-util.h @@ -794,10 +794,7 @@ internal::ParamGenerator ValuesIn( namespace internal { // Used in the Values() function to provide polymorphic capabilities. -#ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable : 4100) -#endif +GTEST_DISABLE_MSC_WARNINGS_PUSH_(4100) template class ValueArray { @@ -818,9 +815,7 @@ class ValueArray { FlatTuple v_; }; -#ifdef _MSC_VER -#pragma warning(pop) -#endif +GTEST_DISABLE_MSC_WARNINGS_POP_() // 4100 template class CartesianProductGenerator -- cgit v0.12