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
This commit is contained in:
Tom Hughes 2023-01-30 13:44:59 -08:00 committed by Copybara-Service
parent f1c05d4544
commit 4fb7039fda
17 changed files with 72 additions and 149 deletions

View File

@ -146,10 +146,7 @@
#include "gmock/internal/gmock-port.h" #include "gmock/internal/gmock-port.h"
#include "gmock/internal/gmock-pp.h" #include "gmock/internal/gmock-pp.h"
#ifdef _MSC_VER GTEST_DISABLE_MSC_WARNINGS_PUSH_(4100)
#pragma warning(push)
#pragma warning(disable : 4100)
#endif
namespace testing { namespace testing {
@ -2295,8 +2292,6 @@ template <typename F, typename Impl>
} // namespace testing } // namespace testing
#ifdef _MSC_VER GTEST_DISABLE_MSC_WARNINGS_POP_() // 4100
#pragma warning(pop)
#endif
#endif // GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_ #endif // GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_

View File

@ -583,10 +583,7 @@ namespace testing {
// the macro definition, as the warnings are generated when the macro // the macro definition, as the warnings are generated when the macro
// is expanded and macro expansion cannot contain #pragma. Therefore // is expanded and macro expansion cannot contain #pragma. Therefore
// we suppress them here. // we suppress them here.
#ifdef _MSC_VER GTEST_DISABLE_MSC_WARNINGS_PUSH_(4100)
#pragma warning(push)
#pragma warning(disable : 4100)
#endif
namespace internal { namespace internal {
@ -654,9 +651,7 @@ InvokeArgument(Params &&...params) {
internal::FlatTupleConstructTag{}, std::forward<Params>(params)...)}; internal::FlatTupleConstructTag{}, std::forward<Params>(params)...)};
} }
#ifdef _MSC_VER GTEST_DISABLE_MSC_WARNINGS_POP_() // 4100
#pragma warning(pop)
#endif
} // namespace testing } // namespace testing

View File

@ -49,14 +49,11 @@ namespace testing {
// Silence C4100 (unreferenced formal // Silence C4100 (unreferenced formal
// parameter) for MSVC // parameter) for MSVC
#ifdef _MSC_VER GTEST_DISABLE_MSC_WARNINGS_PUSH_(4100)
#pragma warning(push) #if defined(_MSC_VER) && (_MSC_VER == 1900)
#pragma warning(disable : 4100)
#if (_MSC_VER == 1900)
// and silence C4800 (C4800: 'int *const ': forcing value // and silence C4800 (C4800: 'int *const ': forcing value
// to bool 'true' or 'false') for MSVC 14 // to bool 'true' or 'false') for MSVC 14
#pragma warning(disable : 4800) GTEST_DISABLE_MSC_WARNINGS_PUSH_(4800)
#endif
#endif #endif
namespace internal { namespace internal {
@ -113,9 +110,10 @@ MATCHER(IsFalse, negation ? "is true" : "is false") {
return !static_cast<bool>(arg); return !static_cast<bool>(arg);
} }
#ifdef _MSC_VER #if defined(_MSC_VER) && (_MSC_VER == 1900)
#pragma warning(pop) GTEST_DISABLE_MSC_WARNINGS_POP_() // 4800
#endif #endif
GTEST_DISABLE_MSC_WARNINGS_POP_() // 4100
} // namespace testing } // namespace testing

View File

@ -58,11 +58,7 @@ namespace internal {
// Silence MSVC C4100 (unreferenced formal parameter) and // Silence MSVC C4100 (unreferenced formal parameter) and
// C4805('==': unsafe mix of type 'const int' and type 'const bool') // C4805('==': unsafe mix of type 'const int' and type 'const bool')
#ifdef _MSC_VER GTEST_DISABLE_MSC_WARNINGS_PUSH_(4100 4805)
#pragma warning(push)
#pragma warning(disable : 4100)
#pragma warning(disable : 4805)
#endif
// Joins a vector of strings as if they are fields of a tuple; returns // Joins a vector of strings as if they are fields of a tuple; returns
// the joined string. // the joined string.
@ -480,9 +476,7 @@ using TupleElement = typename std::tuple_element<I, T>::type;
bool Base64Unescape(const std::string& encoded, std::string* decoded); bool Base64Unescape(const std::string& encoded, std::string* decoded);
#ifdef _MSC_VER GTEST_DISABLE_MSC_WARNINGS_POP_() // 4100 4805
#pragma warning(pop)
#endif
} // namespace internal } // namespace internal
} // namespace testing } // namespace testing

View File

@ -57,11 +57,8 @@
// Silence C4800 (C4800: 'int *const ': forcing value // Silence C4800 (C4800: 'int *const ': forcing value
// to bool 'true' or 'false') for MSVC 15 // to bool 'true' or 'false') for MSVC 15
#ifdef _MSC_VER #if defined(_MSC_VER) && (_MSC_VER == 1900)
#if _MSC_VER == 1900 GTEST_DISABLE_MSC_WARNINGS_PUSH_(4800)
#pragma warning(push)
#pragma warning(disable : 4800)
#endif
#endif #endif
namespace testing { namespace testing {
@ -788,8 +785,6 @@ InSequence::~InSequence() {
} // namespace testing } // namespace testing
#ifdef _MSC_VER #if defined(_MSC_VER) && (_MSC_VER == 1900)
#if _MSC_VER == 1900 GTEST_DISABLE_MSC_WARNINGS_POP_() // 4800
#pragma warning(pop)
#endif
#endif #endif

View File

@ -31,19 +31,6 @@
// //
// This file tests the built-in actions. // 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 "gmock/gmock-actions.h"
#include <algorithm> #include <algorithm>
@ -59,6 +46,15 @@
#include "gtest/gtest-spi.h" #include "gtest/gtest-spi.h"
#include "gtest/gtest.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 testing {
namespace { namespace {
@ -2165,3 +2161,8 @@ TEST(ActionMacro, LargeArity) {
} // namespace } // namespace
} // namespace testing } // namespace testing
#if defined(_MSC_VER) && (_MSC_VER == 1900)
GTEST_DISABLE_MSC_WARNINGS_POP_() // 4800
#endif
GTEST_DISABLE_MSC_WARNINGS_POP_() // 4100 4503

View File

@ -27,17 +27,14 @@
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. // 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. // Google Mock - a framework for writing C++ mock classes.
// //
// This file tests the function mocker classes. // This file tests the function mocker classes.
#include "gmock/gmock-function-mocker.h" #include "gmock/gmock-function-mocker.h"
// Silence C4503 (decorated name length exceeded) for MSVC.
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4503)
#if GTEST_OS_WINDOWS #if GTEST_OS_WINDOWS
// MSDN says the header file to be included for STDMETHOD is BaseTyps.h but // 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 // 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 // significant in determining whether two virtual functions had the same
// signature. This was fixed in Visual Studio 2008. However, the compiler // signature. This was fixed in Visual Studio 2008. However, the compiler
// still emits a warning that alerts about this change in behavior. // still emits a warning that alerts about this change in behavior.
#ifdef _MSC_VER GTEST_DISABLE_MSC_WARNINGS_PUSH_(4373)
#pragma warning(push)
#pragma warning(disable : 4373)
#endif
class MockFoo : public FooInterface { class MockFoo : public FooInterface {
public: public:
MockFoo() {} MockFoo() {}
@ -285,9 +279,7 @@ class LegacyMockFoo : public FooInterface {
LegacyMockFoo& operator=(const LegacyMockFoo&) = delete; LegacyMockFoo& operator=(const LegacyMockFoo&) = delete;
}; };
#ifdef _MSC_VER GTEST_DISABLE_MSC_WARNINGS_POP_() // 4373
#pragma warning(pop)
#endif
template <class T> template <class T>
class FunctionMockerTest : public testing::Test { class FunctionMockerTest : public testing::Test {
@ -1002,3 +994,5 @@ TEST(MockMethodMockFunctionTest, NoexceptSpecifierPreserved) {
} // namespace gmock_function_mocker_test } // namespace gmock_function_mocker_test
} // namespace testing } // namespace testing
GTEST_DISABLE_MSC_WARNINGS_POP_() // 4503

View File

@ -31,18 +31,14 @@
// //
// This file tests some commonly used argument matchers. // 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 "test/gmock-matchers_test.h"
#include <limits> #include <limits>
// 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 testing {
namespace gmock_matchers_test { namespace gmock_matchers_test {
namespace { namespace {
@ -1514,6 +1510,4 @@ TEST(AnyOfTest, WorksOnMoveOnlyType) {
} // namespace gmock_matchers_test } // namespace gmock_matchers_test
} // namespace testing } // namespace testing
#ifdef _MSC_VER GTEST_DISABLE_MSC_WARNINGS_POP_() // 4244 4100
#pragma warning(pop)
#endif

View File

@ -31,18 +31,15 @@
// //
// This file tests some commonly used argument matchers. // 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 <vector> #include <vector>
#include "test/gmock-matchers_test.h" #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 testing {
namespace gmock_matchers_test { namespace gmock_matchers_test {
namespace { namespace {
@ -2354,6 +2351,4 @@ TEST(PolymorphicMatcherTest, CanAccessImpl) {
} // namespace gmock_matchers_test } // namespace gmock_matchers_test
} // namespace testing } // namespace testing
#ifdef _MSC_VER GTEST_DISABLE_MSC_WARNINGS_POP_() // 4244 4100
#pragma warning(pop)
#endif

View File

@ -31,13 +31,11 @@
// //
// This file tests some commonly used argument matchers. // This file tests some commonly used argument matchers.
#include "gtest/gtest.h"
// Silence warning C4244: 'initializing': conversion from 'int' to 'short', // Silence warning C4244: 'initializing': conversion from 'int' to 'short',
// possible loss of data and C4100, unreferenced local parameter // possible loss of data and C4100, unreferenced local parameter
#ifdef _MSC_VER GTEST_DISABLE_MSC_WARNINGS_PUSH_(4244 4100)
#pragma warning(push)
#pragma warning(disable : 4244)
#pragma warning(disable : 4100)
#endif
#include "test/gmock-matchers_test.h" #include "test/gmock-matchers_test.h"
@ -3124,6 +3122,4 @@ TEST(ContainsTest, WorksForTwoDimensionalNativeArray) {
} // namespace gmock_matchers_test } // namespace gmock_matchers_test
} // namespace testing } // namespace testing
#ifdef _MSC_VER GTEST_DISABLE_MSC_WARNINGS_POP_() // 4244 4100
#pragma warning(pop)
#endif

View File

@ -31,13 +31,11 @@
// //
// This file tests some commonly used argument matchers. // This file tests some commonly used argument matchers.
#include "gtest/gtest.h"
// Silence warning C4244: 'initializing': conversion from 'int' to 'short', // Silence warning C4244: 'initializing': conversion from 'int' to 'short',
// possible loss of data and C4100, unreferenced local parameter // possible loss of data and C4100, unreferenced local parameter
#ifdef _MSC_VER GTEST_DISABLE_MSC_WARNINGS_PUSH_(4244 4100)
#pragma warning(push)
#pragma warning(disable : 4244)
#pragma warning(disable : 4100)
#endif
#include "test/gmock-matchers_test.h" #include "test/gmock-matchers_test.h"
@ -1814,6 +1812,4 @@ TEST(ThrowsPredicateCompilesTest, MessageMatcherAcceptsNonMatcher) {
} // namespace gmock_matchers_test } // namespace gmock_matchers_test
} // namespace testing } // namespace testing
#ifdef _MSC_VER GTEST_DISABLE_MSC_WARNINGS_POP_() // 4244 4100
#pragma warning(pop)
#endif

View File

@ -31,11 +31,6 @@
// //
// This file tests the built-in actions in gmock-actions.h. // 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 "gmock/gmock-more-actions.h"
#include <functional> #include <functional>
@ -47,6 +42,8 @@
#include "gtest/gtest-spi.h" #include "gtest/gtest-spi.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4577)
namespace testing { namespace testing {
namespace gmock_more_actions_test { namespace gmock_more_actions_test {
@ -982,11 +979,7 @@ TEST(DoAllTest, ImplicitlyConvertsActionArguments) {
// is expanded and macro expansion cannot contain #pragma. Therefore // is expanded and macro expansion cannot contain #pragma. Therefore
// we suppress them here. // we suppress them here.
// Also suppress C4503 decorated name length exceeded, name was truncated // Also suppress C4503 decorated name length exceeded, name was truncated
#ifdef _MSC_VER GTEST_DISABLE_MSC_WARNINGS_PUSH_(4100 4503)
#pragma warning(push)
#pragma warning(disable : 4100)
#pragma warning(disable : 4503)
#endif
// Tests the ACTION*() macro family. // Tests the ACTION*() macro family.
// Tests that ACTION() can define an action that doesn't reference the // 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 gmock_more_actions_test
} // namespace testing } // namespace testing
GTEST_DISABLE_MSC_WARNINGS_POP_() // 4100 4503
GTEST_DISABLE_MSC_WARNINGS_POP_() // 4577

View File

@ -1779,16 +1779,11 @@ TEST(DeletingMockEarlyTest, Success2) {
// Suppresses warning on unreferenced formal parameter in MSVC with // Suppresses warning on unreferenced formal parameter in MSVC with
// -W4. // -W4.
#ifdef _MSC_VER GTEST_DISABLE_MSC_WARNINGS_PUSH_(4100)
#pragma warning(push)
#pragma warning(disable : 4100)
#endif
ACTION_P(Delete, ptr) { delete ptr; } ACTION_P(Delete, ptr) { delete ptr; }
#ifdef _MSC_VER GTEST_DISABLE_MSC_WARNINGS_POP_() // 4100
#pragma warning(pop)
#endif
TEST(DeletingMockEarlyTest, CanDeleteSelfInActionReturningVoid) { TEST(DeletingMockEarlyTest, CanDeleteSelfInActionReturningVoid) {
MockA* const a = new MockA; MockA* const a = new MockA;

View File

@ -423,10 +423,7 @@ TEST(LinkTest, TestThrow) {
// the macro definition, as the warnings are generated when the macro // the macro definition, as the warnings are generated when the macro
// is expanded and macro expansion cannot contain #pragma. Therefore // is expanded and macro expansion cannot contain #pragma. Therefore
// we suppress them here. // we suppress them here.
#ifdef _MSC_VER GTEST_DISABLE_MSC_WARNINGS_PUSH_(4100)
#pragma warning(push)
#pragma warning(disable : 4100)
#endif
// Tests the linkage of actions created using ACTION macro. // Tests the linkage of actions created using ACTION macro.
namespace { namespace {
@ -459,9 +456,7 @@ ACTION_P2(ReturnEqualsEitherOf, first, second) {
} }
} // namespace } // namespace
#ifdef _MSC_VER GTEST_DISABLE_MSC_WARNINGS_POP_() // 4100
#pragma warning(pop)
#endif
TEST(LinkTest, TestActionP2Macro) { TEST(LinkTest, TestActionP2Macro) {
Mock mock; Mock mock;

View File

@ -38,10 +38,7 @@
#include "gtest/gtest.h" #include "gtest/gtest.h"
// Silence C4100 (unreferenced formal parameter) // Silence C4100 (unreferenced formal parameter)
#ifdef _MSC_VER GTEST_DISABLE_MSC_WARNINGS_PUSH_(4100)
#pragma warning(push)
#pragma warning(disable : 4100)
#endif
using testing::_; using testing::_;
using testing::AnyNumber; using testing::AnyNumber;
@ -286,6 +283,4 @@ int main(int argc, char** argv) {
return RUN_ALL_TESTS(); return RUN_ALL_TESTS();
} }
#ifdef _MSC_VER GTEST_DISABLE_MSC_WARNINGS_POP_() // 4100
#pragma warning(pop)
#endif

View File

@ -166,11 +166,7 @@ namespace testing {
// Silence C4100 (unreferenced formal parameter) and 4805 // Silence C4100 (unreferenced formal parameter) and 4805
// unsafe mix of type 'const int' and type 'const bool' // unsafe mix of type 'const int' and type 'const bool'
#ifdef _MSC_VER GTEST_DISABLE_MSC_WARNINGS_PUSH_(4805 4100)
#pragma warning(push)
#pragma warning(disable : 4805)
#pragma warning(disable : 4100)
#endif
// The upper limit for valid stack trace depths. // The upper limit for valid stack trace depths.
const int kMaxStackTraceDepth = 100; const int kMaxStackTraceDepth = 100;
@ -2214,9 +2210,7 @@ GTEST_API_ std::string TempDir();
// in it should be considered read-only. // in it should be considered read-only.
GTEST_API_ std::string SrcDir(); GTEST_API_ std::string SrcDir();
#ifdef _MSC_VER GTEST_DISABLE_MSC_WARNINGS_POP_() // 4805 4100
#pragma warning(pop)
#endif
// Dynamically registers a test with the framework. // Dynamically registers a test with the framework.
// //

View File

@ -794,10 +794,7 @@ internal::ParamGenerator<typename Container::value_type> ValuesIn(
namespace internal { namespace internal {
// Used in the Values() function to provide polymorphic capabilities. // Used in the Values() function to provide polymorphic capabilities.
#ifdef _MSC_VER GTEST_DISABLE_MSC_WARNINGS_PUSH_(4100)
#pragma warning(push)
#pragma warning(disable : 4100)
#endif
template <typename... Ts> template <typename... Ts>
class ValueArray { class ValueArray {
@ -818,9 +815,7 @@ class ValueArray {
FlatTuple<Ts...> v_; FlatTuple<Ts...> v_;
}; };
#ifdef _MSC_VER GTEST_DISABLE_MSC_WARNINGS_POP_() // 4100
#pragma warning(pop)
#endif
template <typename... T> template <typename... T>
class CartesianProductGenerator class CartesianProductGenerator