From 7bffdde13fc2b5f9dcf8120c1c50e5a5fae1f42c Mon Sep 17 00:00:00 2001 From: Chad Walters Date: Mon, 13 Mar 2017 11:08:48 -0700 Subject: [PATCH] [C++] Don't include warning.h for VC14 and later --- CHANGELOG.md | 10 ++++------ cmake/Config.cmake | 6 ++++-- cpp/inc/bond/core/bonded_void.h | 14 ++++++++++++++ cpp/inc/bond/core/warning.h | 9 +++++++++ cpp/test/comm/main.cpp | 11 +++++++++++ cpp/test/core/main.cpp | 10 ++++++++++ cpp/test/core/merge_test.cpp | 15 +++++++++++++++ cpp/test/core/pass_through.cpp | 7 +++++++ cpp/test/core/unit_test_util.h | 18 ++++++++++++++++-- 9 files changed, 90 insertions(+), 10 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e291ada7a..5cffca0e1c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,8 +15,7 @@ different versioning scheme, following the Haskell community's * `gbc` & compiler library: TBD (minor bump needed) * IDL core version: TBD * IDL comm version: TBD -* C++ version: TBD (major bump needed) ->>>>>>> [c++] Avoid name shadowing warnings +* C++ version: TBD (minor bump needed) * C# NuGet version: TBD (minor bump needed) * C# Comm NuGet version: TBD (minor bump needed) @@ -33,10 +32,9 @@ different versioning scheme, following the Haskell community's [`_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES`](https://msdn.microsoft.com/en-us/library/ms175759.aspx) instead of `_CTR_SECURE_NO_WARNINGS`. * Bond builds on MSVC with SDL recommended warnings enabled. -* **Breaking change:** Suppression of MSVC name shadowing warnings is no - longed needed, and Bond's warning.h header no longer supresses C4456, - C4458, or C4459. This may cause these warnings to now be triggered on - other code. +* Eliminate need for warning suppression on MSVC14 via warning.h in Bond + itself. warning.h is still in place on MSVC12; furthermore, we don't alter + warning.h for now as it may be depended upon by application code. ## C# ### diff --git a/cmake/Config.cmake b/cmake/Config.cmake index 311f8eae35..d494166770 100644 --- a/cmake/Config.cmake +++ b/cmake/Config.cmake @@ -21,8 +21,10 @@ endif() if (MSVC) # MSVC needs this because of how template-heavy our code is. add_compile_options (/bigobj) - # inject disabling of some MSVC warnings - add_compile_options (/FIbond/core/warning.h) + # inject disabling of some MSVC warnings for versions prior to MSVC14 + if (MSVC_VERSION LESS 1900) + add_compile_options (/FIbond/core/warning.h) + endif() # turn up warning level add_compile_options (/W4 /WX /sdl) # Enable SDL recommended warnings that aren't enabled by /W4 diff --git a/cpp/inc/bond/core/bonded_void.h b/cpp/inc/bond/core/bonded_void.h index ca36691a30..29beb7d670 100644 --- a/cpp/inc/bond/core/bonded_void.h +++ b/cpp/inc/bond/core/bonded_void.h @@ -111,7 +111,14 @@ class bonded template void Deserialize(bonded& var) const { +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable: 4127) // C4127: conditional expression is constant +#endif if (uses_marshaled_bonded::value && _schema.GetType().bonded_type) +#ifdef _MSC_VER +#pragma warning(pop) +#endif { bonded tmp; _SelectProtocolAndApply(boost::ref(tmp)); @@ -148,7 +155,14 @@ class bonded template bool _Apply(const Transform& transform) const { +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable: 4127) // C4127: conditional expression is constant +#endif if (uses_marshaled_bonded::value && _schema.GetType().bonded_type) +#ifdef _MSC_VER +#pragma warning(pop) +#endif { return _SelectProtocolAndApply(transform); } diff --git a/cpp/inc/bond/core/warning.h b/cpp/inc/bond/core/warning.h index 50916d59fc..2b70cfaea1 100644 --- a/cpp/inc/bond/core/warning.h +++ b/cpp/inc/bond/core/warning.h @@ -23,5 +23,14 @@ // C4482: nonstandard extension used: enum 'enum' used in qualified name #pragma warning(disable: 4482) +// C4456: declaration of 'symbol' hides previous local declaration +#pragma warning(disable: 4456) + +// C4458: declaration of 'symbol' hides class member +#pragma warning(disable: 4458) + +// C4458: declaration of 'symbol' hides global declaration +#pragma warning(disable: 4459) + // C4512: assignment operator could not be generated #pragma warning(disable: 4512) diff --git a/cpp/test/comm/main.cpp b/cpp/test/comm/main.cpp index 631bd8bffc..032745d790 100644 --- a/cpp/test/comm/main.cpp +++ b/cpp/test/comm/main.cpp @@ -8,12 +8,23 @@ * Using boost/test/included/unit_test.hpp on *nix causes segfaults during * teardown in some suites. */ + + +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable: 4702) // C4702: unreachable code +#endif + #if defined(_WIN32) #include #else #include #endif +#ifdef _MSC_VER +#pragma warning(pop) +#endif + #include "../core/unit_test_framework.h" #include "../logging.h" #include "test_utils_comm.h" diff --git a/cpp/test/core/main.cpp b/cpp/test/core/main.cpp index c699edff74..e71bc74659 100644 --- a/cpp/test/core/main.cpp +++ b/cpp/test/core/main.cpp @@ -8,12 +8,22 @@ * Using boost/test/included/unit_test.hpp on *nix causes segfaults during * teardown in some suites. */ + +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable: 4702) // C4702: unreachable code +#endif + #if defined(_WIN32) #include #else #include #endif +#ifdef _MSC_VER +#pragma warning(pop) +#endif + #include "../logging.h" extern bool init_unit_test(); diff --git a/cpp/test/core/merge_test.cpp b/cpp/test/core/merge_test.cpp index c991228464..4fe2077c5d 100644 --- a/cpp/test/core/merge_test.cpp +++ b/cpp/test/core/merge_test.cpp @@ -15,7 +15,15 @@ void Merging(Payload payload, const T& obj, uint16_t version = bond::v1, bool me { T to; +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable: 4127) // C4127: conditional expression is constant +#endif if (boost::mpl::count_if >::value == 0) +#ifdef _MSC_VER +#pragma warning(pop) +#endif + { to = InitRandom(); Fixup(to); @@ -31,7 +39,14 @@ void Merging(Payload payload, const T& obj, uint16_t version = bond::v1, bool me { Payload to; +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable: 4127) // C4127: conditional expression is constant +#endif if (boost::mpl::count_if >::value == 0) +#ifdef _MSC_VER +#pragma warning(pop) +#endif { to = InitRandom(); Fixup(to); diff --git a/cpp/test/core/pass_through.cpp b/cpp/test/core/pass_through.cpp index e125fc45ba..340f9a5d2a 100644 --- a/cpp/test/core/pass_through.cpp +++ b/cpp/test/core/pass_through.cpp @@ -373,7 +373,14 @@ TEST_CASE_BEGIN(DefaultValuesTranscoding) T init; +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable: 4127) // C4127: conditional expression is constant +#endif if (bond::uses_dynamic_parser::value && !bond::may_omit_fields::value) +#ifdef _MSC_VER +#pragma warning(pop) +#endif { // transcoding from tagged protocol using runtime schema fills-in default values // so we can use random object as initial value of 'to'. diff --git a/cpp/test/core/unit_test_util.h b/cpp/test/core/unit_test_util.h index 296b9309b8..d281ef2192 100644 --- a/cpp/test/core/unit_test_util.h +++ b/cpp/test/core/unit_test_util.h @@ -379,8 +379,15 @@ void Binding(const From& from, uint16_t version = bond::v1) bond::bonded bonded(GetBonded(from, version)); To to; - + +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable: 4127) // C4127: conditional expression is constant +#endif if (boost::mpl::count_if >::value == 0) +#ifdef _MSC_VER +#pragma warning(pop) +#endif { to = InitRandom(); Fixup(to); @@ -396,8 +403,15 @@ void Binding(const From& from, uint16_t version = bond::v1) bond::bonded bonded(GetBonded(from, version)); To to; - + +#ifdef _MSC_VER +#pragma warning(push) +#pragma warning(disable: 4127) // C4127: conditional expression is constant +#endif if (boost::mpl::count_if >::value == 0) +#ifdef _MSC_VER +#pragma warning(pop) +#endif { to = InitRandom(); Fixup(to);