Skip to content

Commit 4fb7039

Browse files
thughescopybara-github
authored andcommitted
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
1 parent f1c05d4 commit 4fb7039

17 files changed

+72
-149
lines changed

googlemock/include/gmock/gmock-actions.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,7 @@
146146
#include "gmock/internal/gmock-port.h"
147147
#include "gmock/internal/gmock-pp.h"
148148

149-
#ifdef _MSC_VER
150-
#pragma warning(push)
151-
#pragma warning(disable : 4100)
152-
#endif
149+
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4100)
153150

154151
namespace testing {
155152

@@ -2295,8 +2292,6 @@ ::testing::Action<F> MakeAction(std::shared_ptr<Impl> impl) {
22952292

22962293
} // namespace testing
22972294

2298-
#ifdef _MSC_VER
2299-
#pragma warning(pop)
2300-
#endif
2295+
GTEST_DISABLE_MSC_WARNINGS_POP_() // 4100
23012296

23022297
#endif // GOOGLEMOCK_INCLUDE_GMOCK_GMOCK_ACTIONS_H_

googlemock/include/gmock/gmock-more-actions.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -583,10 +583,7 @@ namespace testing {
583583
// the macro definition, as the warnings are generated when the macro
584584
// is expanded and macro expansion cannot contain #pragma. Therefore
585585
// we suppress them here.
586-
#ifdef _MSC_VER
587-
#pragma warning(push)
588-
#pragma warning(disable : 4100)
589-
#endif
586+
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4100)
590587

591588
namespace internal {
592589

@@ -654,9 +651,7 @@ InvokeArgument(Params &&...params) {
654651
internal::FlatTupleConstructTag{}, std::forward<Params>(params)...)};
655652
}
656653

657-
#ifdef _MSC_VER
658-
#pragma warning(pop)
659-
#endif
654+
GTEST_DISABLE_MSC_WARNINGS_POP_() // 4100
660655

661656
} // namespace testing
662657

googlemock/include/gmock/gmock-more-matchers.h

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,11 @@ namespace testing {
4949

5050
// Silence C4100 (unreferenced formal
5151
// parameter) for MSVC
52-
#ifdef _MSC_VER
53-
#pragma warning(push)
54-
#pragma warning(disable : 4100)
55-
#if (_MSC_VER == 1900)
52+
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4100)
53+
#if defined(_MSC_VER) && (_MSC_VER == 1900)
5654
// and silence C4800 (C4800: 'int *const ': forcing value
5755
// to bool 'true' or 'false') for MSVC 14
58-
#pragma warning(disable : 4800)
59-
#endif
56+
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4800)
6057
#endif
6158

6259
namespace internal {
@@ -113,9 +110,10 @@ MATCHER(IsFalse, negation ? "is true" : "is false") {
113110
return !static_cast<bool>(arg);
114111
}
115112

116-
#ifdef _MSC_VER
117-
#pragma warning(pop)
113+
#if defined(_MSC_VER) && (_MSC_VER == 1900)
114+
GTEST_DISABLE_MSC_WARNINGS_POP_() // 4800
118115
#endif
116+
GTEST_DISABLE_MSC_WARNINGS_POP_() // 4100
119117

120118
} // namespace testing
121119

googlemock/include/gmock/internal/gmock-internal-utils.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,7 @@ namespace internal {
5858

5959
// Silence MSVC C4100 (unreferenced formal parameter) and
6060
// C4805('==': unsafe mix of type 'const int' and type 'const bool')
61-
#ifdef _MSC_VER
62-
#pragma warning(push)
63-
#pragma warning(disable : 4100)
64-
#pragma warning(disable : 4805)
65-
#endif
61+
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4100 4805)
6662

6763
// Joins a vector of strings as if they are fields of a tuple; returns
6864
// the joined string.
@@ -480,9 +476,7 @@ using TupleElement = typename std::tuple_element<I, T>::type;
480476

481477
bool Base64Unescape(const std::string& encoded, std::string* decoded);
482478

483-
#ifdef _MSC_VER
484-
#pragma warning(pop)
485-
#endif
479+
GTEST_DISABLE_MSC_WARNINGS_POP_() // 4100 4805
486480

487481
} // namespace internal
488482
} // namespace testing

googlemock/src/gmock-spec-builders.cc

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,8 @@
5757

5858
// Silence C4800 (C4800: 'int *const ': forcing value
5959
// to bool 'true' or 'false') for MSVC 15
60-
#ifdef _MSC_VER
61-
#if _MSC_VER == 1900
62-
#pragma warning(push)
63-
#pragma warning(disable : 4800)
64-
#endif
60+
#if defined(_MSC_VER) && (_MSC_VER == 1900)
61+
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4800)
6562
#endif
6663

6764
namespace testing {
@@ -788,8 +785,6 @@ InSequence::~InSequence() {
788785

789786
} // namespace testing
790787

791-
#ifdef _MSC_VER
792-
#if _MSC_VER == 1900
793-
#pragma warning(pop)
794-
#endif
788+
#if defined(_MSC_VER) && (_MSC_VER == 1900)
789+
GTEST_DISABLE_MSC_WARNINGS_POP_() // 4800
795790
#endif

googlemock/test/gmock-actions_test.cc

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,6 @@
3131
//
3232
// This file tests the built-in actions.
3333

34-
// Silence C4100 (unreferenced formal parameter) and C4503 (decorated name
35-
// length exceeded) for MSVC.
36-
#ifdef _MSC_VER
37-
#pragma warning(push)
38-
#pragma warning(disable : 4100)
39-
#pragma warning(disable : 4503)
40-
#if _MSC_VER == 1900
41-
// and silence C4800 (C4800: 'int *const ': forcing value
42-
// to bool 'true' or 'false') for MSVC 15
43-
#pragma warning(disable : 4800)
44-
#endif
45-
#endif
46-
4734
#include "gmock/gmock-actions.h"
4835

4936
#include <algorithm>
@@ -59,6 +46,15 @@
5946
#include "gtest/gtest-spi.h"
6047
#include "gtest/gtest.h"
6148

49+
// Silence C4100 (unreferenced formal parameter) and C4503 (decorated name
50+
// length exceeded) for MSVC.
51+
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4100 4503)
52+
#if defined(_MSC_VER) && (_MSC_VER == 1900)
53+
// and silence C4800 (C4800: 'int *const ': forcing value
54+
// to bool 'true' or 'false') for MSVC 15
55+
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4800)
56+
#endif
57+
6258
namespace testing {
6359
namespace {
6460

@@ -2165,3 +2161,8 @@ TEST(ActionMacro, LargeArity) {
21652161

21662162
} // namespace
21672163
} // namespace testing
2164+
2165+
#if defined(_MSC_VER) && (_MSC_VER == 1900)
2166+
GTEST_DISABLE_MSC_WARNINGS_POP_() // 4800
2167+
#endif
2168+
GTEST_DISABLE_MSC_WARNINGS_POP_() // 4100 4503

googlemock/test/gmock-function-mocker_test.cc

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,14 @@
2727
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2828
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2929

30-
// Silence C4503 (decorated name length exceeded) for MSVC.
31-
#ifdef _MSC_VER
32-
#pragma warning(push)
33-
#pragma warning(disable : 4503)
34-
#endif
35-
3630
// Google Mock - a framework for writing C++ mock classes.
3731
//
3832
// This file tests the function mocker classes.
3933
#include "gmock/gmock-function-mocker.h"
4034

35+
// Silence C4503 (decorated name length exceeded) for MSVC.
36+
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4503)
37+
4138
#if GTEST_OS_WINDOWS
4239
// MSDN says the header file to be included for STDMETHOD is BaseTyps.h but
4340
// we are getting compiler errors if we use basetyps.h, hence including
@@ -137,10 +134,7 @@ class FooInterface {
137134
// significant in determining whether two virtual functions had the same
138135
// signature. This was fixed in Visual Studio 2008. However, the compiler
139136
// still emits a warning that alerts about this change in behavior.
140-
#ifdef _MSC_VER
141-
#pragma warning(push)
142-
#pragma warning(disable : 4373)
143-
#endif
137+
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4373)
144138
class MockFoo : public FooInterface {
145139
public:
146140
MockFoo() {}
@@ -285,9 +279,7 @@ class LegacyMockFoo : public FooInterface {
285279
LegacyMockFoo& operator=(const LegacyMockFoo&) = delete;
286280
};
287281

288-
#ifdef _MSC_VER
289-
#pragma warning(pop)
290-
#endif
282+
GTEST_DISABLE_MSC_WARNINGS_POP_() // 4373
291283

292284
template <class T>
293285
class FunctionMockerTest : public testing::Test {
@@ -1002,3 +994,5 @@ TEST(MockMethodMockFunctionTest, NoexceptSpecifierPreserved) {
1002994

1003995
} // namespace gmock_function_mocker_test
1004996
} // namespace testing
997+
998+
GTEST_DISABLE_MSC_WARNINGS_POP_() // 4503

googlemock/test/gmock-matchers-arithmetic_test.cc

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,14 @@
3131
//
3232
// This file tests some commonly used argument matchers.
3333

34-
// Silence warning C4244: 'initializing': conversion from 'int' to 'short',
35-
// possible loss of data and C4100, unreferenced local parameter
36-
#ifdef _MSC_VER
37-
#pragma warning(push)
38-
#pragma warning(disable : 4244)
39-
#pragma warning(disable : 4100)
40-
#endif
41-
4234
#include "test/gmock-matchers_test.h"
4335

4436
#include <limits>
4537

38+
// Silence warning C4244: 'initializing': conversion from 'int' to 'short',
39+
// possible loss of data and C4100, unreferenced local parameter
40+
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4244 4100)
41+
4642
namespace testing {
4743
namespace gmock_matchers_test {
4844
namespace {
@@ -1514,6 +1510,4 @@ TEST(AnyOfTest, WorksOnMoveOnlyType) {
15141510
} // namespace gmock_matchers_test
15151511
} // namespace testing
15161512

1517-
#ifdef _MSC_VER
1518-
#pragma warning(pop)
1519-
#endif
1513+
GTEST_DISABLE_MSC_WARNINGS_POP_() // 4244 4100

googlemock/test/gmock-matchers-comparisons_test.cc

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,15 @@
3131
//
3232
// This file tests some commonly used argument matchers.
3333

34-
// Silence warning C4244: 'initializing': conversion from 'int' to 'short',
35-
// possible loss of data and C4100, unreferenced local parameter
36-
#ifdef _MSC_VER
37-
#pragma warning(push)
38-
#pragma warning(disable : 4244)
39-
#pragma warning(disable : 4100)
40-
#endif
41-
4234
#include <vector>
4335

4436
#include "test/gmock-matchers_test.h"
4537

38+
// Silence warning C4244: 'initializing': conversion from 'int' to 'short',
39+
// possible loss of data and C4100, unreferenced local parameter
40+
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4244 4100)
41+
42+
4643
namespace testing {
4744
namespace gmock_matchers_test {
4845
namespace {
@@ -2354,6 +2351,4 @@ TEST(PolymorphicMatcherTest, CanAccessImpl) {
23542351
} // namespace gmock_matchers_test
23552352
} // namespace testing
23562353

2357-
#ifdef _MSC_VER
2358-
#pragma warning(pop)
2359-
#endif
2354+
GTEST_DISABLE_MSC_WARNINGS_POP_() // 4244 4100

googlemock/test/gmock-matchers-containers_test.cc

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,11 @@
3131
//
3232
// This file tests some commonly used argument matchers.
3333

34+
#include "gtest/gtest.h"
35+
3436
// Silence warning C4244: 'initializing': conversion from 'int' to 'short',
3537
// possible loss of data and C4100, unreferenced local parameter
36-
#ifdef _MSC_VER
37-
#pragma warning(push)
38-
#pragma warning(disable : 4244)
39-
#pragma warning(disable : 4100)
40-
#endif
38+
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4244 4100)
4139

4240
#include "test/gmock-matchers_test.h"
4341

@@ -3124,6 +3122,4 @@ TEST(ContainsTest, WorksForTwoDimensionalNativeArray) {
31243122
} // namespace gmock_matchers_test
31253123
} // namespace testing
31263124

3127-
#ifdef _MSC_VER
3128-
#pragma warning(pop)
3129-
#endif
3125+
GTEST_DISABLE_MSC_WARNINGS_POP_() // 4244 4100

0 commit comments

Comments
 (0)