Do not rely on a define for disabling warnings Using a define to determine whether to disable warnings introduces a dependency on the header inclusion order and thus can prevent the warnings from being enabled. Fixes #1173 Change-Id: I21f5bca78a83bfe4642e9b01abd220b9fbba31a4
diff --git a/include/ceres/internal/disable_warnings.h b/include/ceres/internal/disable_warnings.h index b6e38aa..408698b 100644 --- a/include/ceres/internal/disable_warnings.h +++ b/include/ceres/internal/disable_warnings.h
@@ -1,5 +1,5 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2023 Google Inc. All rights reserved. +// Copyright 2025 Google Inc. All rights reserved. // http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without @@ -28,10 +28,8 @@ // // This file has the sole purpose to silence warnings when including Ceres. -// This is not your usual header guard. The macro CERES_WARNINGS_DISABLED -// shows up again in reenable_warnings.h. -#ifndef CERES_WARNINGS_DISABLED -#define CERES_WARNINGS_DISABLED +// NOTE: An include guard is not necessary and in fact counterproductive because +// #pragma warning(push) will depend on the inclusion order. #ifdef _MSC_VER #pragma warning(push) @@ -40,5 +38,3 @@ // "if you are deriving from a type in the Standard C++ Library" #pragma warning(disable : 4251) #endif - -#endif // CERES_WARNINGS_DISABLED
diff --git a/include/ceres/internal/reenable_warnings.h b/include/ceres/internal/reenable_warnings.h index a183c25..947cdfd 100644 --- a/include/ceres/internal/reenable_warnings.h +++ b/include/ceres/internal/reenable_warnings.h
@@ -1,5 +1,5 @@ // Ceres Solver - A fast non-linear least squares minimizer -// Copyright 2023 Google Inc. All rights reserved. +// Copyright 2025 Google Inc. All rights reserved. // http://ceres-solver.org/ // // Redistribution and use in source and binary forms, with or without @@ -27,12 +27,6 @@ // POSSIBILITY OF SUCH DAMAGE. // -// This is not your usual header guard. See disable_warnings.h -#ifdef CERES_WARNINGS_DISABLED -#undef CERES_WARNINGS_DISABLED - #ifdef _MSC_VER #pragma warning(pop) #endif - -#endif // CERES_WARNINGS_DISABLED