From 73139d403239b1f981045ddb756071d9e95170e4 Mon Sep 17 00:00:00 2001 From: Aaron Gorenstein Date: Tue, 14 Feb 2017 12:04:24 -0800 Subject: [PATCH 1/2] Deliberate-failure tests shouldn't be optimized A few tests designed to deliberately fail appeal to UB (undefined behavior), but as the MSVC optimizer improves we will take advantage of that to remove UB statements. In order for deliberate failures to occur, the tests must have the optimizer turned off. --- doc/examples/example22.run-fail.cpp | 9 +++++++++ doc/examples/example23.run-fail.cpp | 10 ++++++++++ 2 files changed, 19 insertions(+) diff --git a/doc/examples/example22.run-fail.cpp b/doc/examples/example22.run-fail.cpp index 42f0ae2d98..b9c93c4052 100644 --- a/doc/examples/example22.run-fail.cpp +++ b/doc/examples/example22.run-fail.cpp @@ -23,8 +23,17 @@ void goo( int ) { } +#if defined(BOOST_MSVC) +// compiler optimizations may cause this code NOT to crash. +#pragma optimize("", off) +#endif + void foo( int i ) { goo( 2/(i-1) ); } + +#if defined(BOOST_MSVC) +#pragma optimize("", on) +#endif //] diff --git a/doc/examples/example23.run-fail.cpp b/doc/examples/example23.run-fail.cpp index 34b4044857..1b57feef8d 100644 --- a/doc/examples/example23.run-fail.cpp +++ b/doc/examples/example23.run-fail.cpp @@ -9,8 +9,18 @@ #define BOOST_TEST_MODULE example #include +#if defined(BOOST_MSVC) +// compiler optimizations may cause this code NOT to crash. +#pragma optimize("", off) +#endif + + void foo( int ) {} +#if defined(BOOST_MSVC) +#pragma optimize("", on) +#endif + BOOST_AUTO_TEST_CASE( test_case ) { int* p = 0; From 5b2199afb2f313fe9dd0fe4eb961bf4d6d17a376 Mon Sep 17 00:00:00 2001 From: Aaron Gorenstein Date: Tue, 21 Mar 2017 11:36:44 -0700 Subject: [PATCH 2/2] Added BOOST_MSVC version check to test patches --- doc/examples/example22.run-fail.cpp | 6 +++--- doc/examples/example23.run-fail.cpp | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/doc/examples/example22.run-fail.cpp b/doc/examples/example22.run-fail.cpp index b9c93c4052..7bd2bade93 100644 --- a/doc/examples/example22.run-fail.cpp +++ b/doc/examples/example22.run-fail.cpp @@ -23,8 +23,8 @@ void goo( int ) { } -#if defined(BOOST_MSVC) -// compiler optimizations may cause this code NOT to crash. +#if defined(BOOST_MSVC) && (BOOST_MSVC > 1900) +// VS2017+ compiler optimizations may cause this code NOT to crash. #pragma optimize("", off) #endif @@ -33,7 +33,7 @@ void foo( int i ) goo( 2/(i-1) ); } -#if defined(BOOST_MSVC) +#if defined(BOOST_MSVC) && (BOOST_MSVC > 1900) #pragma optimize("", on) #endif //] diff --git a/doc/examples/example23.run-fail.cpp b/doc/examples/example23.run-fail.cpp index 1b57feef8d..5b824b7846 100644 --- a/doc/examples/example23.run-fail.cpp +++ b/doc/examples/example23.run-fail.cpp @@ -9,15 +9,15 @@ #define BOOST_TEST_MODULE example #include -#if defined(BOOST_MSVC) -// compiler optimizations may cause this code NOT to crash. +#if defined(BOOST_MSVC) && (BOOST_MSVC > 1900) +// VS2017+ compiler optimizations may cause this code NOT to crash. #pragma optimize("", off) #endif void foo( int ) {} -#if defined(BOOST_MSVC) +#if defined(BOOST_MSVC) && (BOOST_MSVC > 1900) #pragma optimize("", on) #endif