Skip to content
/ bond Public
forked from microsoft/bond

Commit

Permalink
[C++] Don't include warning.h for VC14 and later
Browse files Browse the repository at this point in the history
  • Loading branch information
Chad Walters committed Mar 17, 2017
1 parent 23fa450 commit 7bffdde
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 10 deletions.
10 changes: 4 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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# ###

Expand Down
6 changes: 4 additions & 2 deletions cmake/Config.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions cpp/inc/bond/core/bonded_void.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,14 @@ class bonded<void, Reader>
template <typename T>
void Deserialize(bonded<T>& var) const
{
#ifdef _MSC_VER
#pragma warning(push)
#pragma warning(disable: 4127) // C4127: conditional expression is constant
#endif
if (uses_marshaled_bonded<Reader>::value && _schema.GetType().bonded_type)
#ifdef _MSC_VER
#pragma warning(pop)
#endif
{
bonded<T> tmp;
_SelectProtocolAndApply(boost::ref(tmp));
Expand Down Expand Up @@ -148,7 +155,14 @@ class bonded<void, Reader>
template <typename Transform>
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<Reader>::value && _schema.GetType().bonded_type)
#ifdef _MSC_VER
#pragma warning(pop)
#endif
{
return _SelectProtocolAndApply(transform);
}
Expand Down
9 changes: 9 additions & 0 deletions cpp/inc/bond/core/warning.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
11 changes: 11 additions & 0 deletions cpp/test/comm/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <boost/test/included/unit_test.hpp>
#else
#include <boost/test/unit_test.hpp>
#endif

#ifdef _MSC_VER
#pragma warning(pop)
#endif

#include "../core/unit_test_framework.h"
#include "../logging.h"
#include "test_utils_comm.h"
Expand Down
10 changes: 10 additions & 0 deletions cpp/test/core/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <boost/test/included/unit_test.hpp>
#else
#include <boost/test/unit_test.hpp>
#endif

#ifdef _MSC_VER
#pragma warning(pop)
#endif

#include "../logging.h"

extern bool init_unit_test();
Expand Down
15 changes: 15 additions & 0 deletions cpp/test/core/merge_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<typename T::Schema::fields, is_optional_field<_> >::value == 0)
#ifdef _MSC_VER
#pragma warning(pop)
#endif

{
to = InitRandom<T>();
Fixup(to);
Expand All @@ -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<typename Payload::Schema::fields, is_optional_field<_> >::value == 0)
#ifdef _MSC_VER
#pragma warning(pop)
#endif
{
to = InitRandom<Payload>();
Fixup(to);
Expand Down
7 changes: 7 additions & 0 deletions cpp/test/core/pass_through.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<Reader1>::value && !bond::may_omit_fields<Writer2>::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'.
Expand Down
18 changes: 16 additions & 2 deletions cpp/test/core/unit_test_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,15 @@ void Binding(const From& from, uint16_t version = bond::v1)
bond::bonded<BondedType> bonded(GetBonded<Reader, Writer, BondedType>(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<typename From::Schema::fields, is_optional_field<_> >::value == 0)
#ifdef _MSC_VER
#pragma warning(pop)
#endif
{
to = InitRandom<To>();
Fixup(to);
Expand All @@ -396,8 +403,15 @@ void Binding(const From& from, uint16_t version = bond::v1)
bond::bonded<void> bonded(GetBonded<Reader, Writer, BondedType>(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<typename From::Schema::fields, is_optional_field<_> >::value == 0)
#ifdef _MSC_VER
#pragma warning(pop)
#endif
{
to = InitRandom<To>();
Fixup(to);
Expand Down

0 comments on commit 7bffdde

Please sign in to comment.