From ab9436cb9e67139f7dbee2f97d728f5b2f71630b Mon Sep 17 00:00:00 2001 From: Sergiu Deitsch Date: Sun, 20 Mar 2022 12:12:51 +0100 Subject: [PATCH] Workaround MSVC STL deficiency in C++17 mode Compiling jet_test using the /std:c++17 switch triggers a C3198 compile error in . Moving #pragma below all the includes, allows to workaround the issue. Additionally, locally ensure the floating-point model is always /fp:precise to be able to access the floating-point environment in jet_test. Change-Id: Ia5b3a3dac13baf46546ac1d0d304fc05512f8816 --- internal/ceres/jet_test.cc | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/internal/ceres/jet_test.cc b/internal/ceres/jet_test.cc index 44db7aa03..6f71b77f6 100644 --- a/internal/ceres/jet_test.cc +++ b/internal/ceres/jet_test.cc @@ -28,17 +28,6 @@ // // Author: keir@google.com (Keir Mierle) -// The floating-point environment access and modification is only meaningful -// with the following pragma. -#ifdef _MSC_VER -#pragma fenv_access(on) -#elif !(defined(__ARM_ARCH) && __ARM_ARCH >= 8) -// NOTE: FENV_ACCESS cannot be set to ON when targeting arm(v8) -#pragma STDC FENV_ACCESS ON -#else -#define CERES_NO_FENV_ACCESS -#endif - #include "ceres/jet.h" #include @@ -52,6 +41,18 @@ #include "gmock/gmock.h" #include "gtest/gtest.h" +// The floating-point environment access and modification is only meaningful +// with the following pragma. +#ifdef _MSC_VER +#pragma float_control(precise, on, push) +#pragma fenv_access(on) +#elif !(defined(__ARM_ARCH) && __ARM_ARCH >= 8) +// NOTE: FENV_ACCESS cannot be set to ON when targeting arm(v8) +#pragma STDC FENV_ACCESS ON +#else +#define CERES_NO_FENV_ACCESS +#endif + namespace ceres { namespace internal { @@ -1293,3 +1294,7 @@ TYPED_TEST(JetTest, Nested3XComparison) { } // namespace internal } // namespace ceres + +#ifdef _MSC_VER +#pragma float_control(pop) +#endif