From 77d7044d231bee7d73dd3456977dbbfdb09e200a Mon Sep 17 00:00:00 2001 From: Sergiu Deitsch Date: Sun, 28 Sep 2025 17:16:47 +0200 Subject: [PATCH] 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 --- include/ceres/internal/disable_warnings.h | 10 +++------- include/ceres/internal/reenable_warnings.h | 8 +------- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/include/ceres/internal/disable_warnings.h b/include/ceres/internal/disable_warnings.h index b6e38aa33..408698b6a 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 a183c2531..947cdfde0 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