From 7ac52347b7885b0e12889fca40f22f106e901089 Mon Sep 17 00:00:00 2001 From: Thomas Jarosch Date: Tue, 30 Dec 2025 10:00:54 +0100 Subject: [PATCH] logfunc: Fix deprecated std::auto_ptr for GCC 4.8.1+ Original warning: src/logfunc.hpp:147:30: error: 'template class std::auto_ptr' is deprecated: use 'std::unique_ptr' instead [-Werror=deprecated-declarations] Use std::auto_ptr for GCC <= 4.7.x and std::unique_ptr for GCC >= 4.8.1. GCC 4.8.1 was the first version with feature-complete C++11 support. This still enables compilation on g++ 4.4.4. --- src/logfunc.cpp | 4 ++++ src/logfunc.hpp | 19 ++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletions(-) diff --git a/src/logfunc.cpp b/src/logfunc.cpp index c6883fc..fd0f4e0 100644 --- a/src/logfunc.cpp +++ b/src/logfunc.cpp @@ -419,7 +419,11 @@ PartLogger::LogHelper::LogHelper(const LogHelper& helper) : Logger(helper.Logger) , Level(helper.Level) , Location(helper.Location) +#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8) +, StreamPtr(std::move(helper.StreamPtr)) +#else , StreamPtr(helper.StreamPtr) +#endif { } // eo PartLogger::LogHelper::LogHelper(const LogHelper&) diff --git a/src/logfunc.hpp b/src/logfunc.hpp index 56b1814..865b9bb 100644 --- a/src/logfunc.hpp +++ b/src/logfunc.hpp @@ -34,6 +34,23 @@ on this file might be covered by the GNU General Public License. #include #include +/* +** std::unique_ptr is available in GCC 4.4, but to be safe +** we use std::auto_ptr for GCC 4.4.x and std::unique_ptr for GCC 4.8.1+. +** GCC 4.8.1 was the first version with feature-complete C++11 support. +** See: https://gcc.gnu.org/projects/cxx-status.html#cxx11 +*/ +#include +#if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 8) +#if __cplusplus < 201103L +#error "This header requires C++11 or higher when compiled with GCC >= 4.8. " \ +"Otherwise we get an ABI mismatch." +#endif +typedef std::unique_ptr< std::ostringstream > StreamPtrType; +#else +typedef std::auto_ptr< std::ostringstream > StreamPtrType; +#endif + #include #include "source_track_basics.hpp" @@ -144,7 +161,7 @@ class PartLogger PartLogger& Logger; int Level; SourceLocation Location; - mutable std::auto_ptr< std::ostringstream > StreamPtr; + mutable StreamPtrType StreamPtr; }; // eo class LogHelper -- 1.7.1