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-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 <typename F, typename Impl>
} // namespace testing
#ifdef _MSC_VER
#pragma warning(pop)
#endif
GTEST_DISABLE_MSC_WARNINGS_POP_() // 4100
#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
// 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>(params)...)};
}
#ifdef _MSC_VER
#pragma warning(pop)
#endif
GTEST_DISABLE_MSC_WARNINGS_POP_() // 4100
} // namespace testing

View File

@ -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<bool>(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

View File

@ -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<I, T>::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

View File

@ -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

View File

@ -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 <algorithm>
@ -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

View File

@ -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 T>
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

View File

@ -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 <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 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

View File

@ -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 <vector>
#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

View File

@ -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

View File

@ -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

View File

@ -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 <functional>
@ -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

View File

@ -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;

View File

@ -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;

View File

@ -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

View File

@ -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.
//

View File

@ -794,10 +794,7 @@ internal::ParamGenerator<typename Container::value_type> 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 <typename... Ts>
class ValueArray {
@ -818,9 +815,7 @@ class ValueArray {
FlatTuple<Ts...> v_;
};
#ifdef _MSC_VER
#pragma warning(pop)
#endif
GTEST_DISABLE_MSC_WARNINGS_POP_() // 4100
template <typename... T>
class CartesianProductGenerator