logfunc: Fix deprecated std::auto_ptr for GCC 4.8.1+
authorThomas Jarosch <thomas.jarosch@intra2net.com>
Tue, 30 Dec 2025 09:00:54 +0000 (10:00 +0100)
committerThomas Jarosch <thomas.jarosch@intra2net.com>
Wed, 31 Dec 2025 11:11:25 +0000 (12:11 +0100)
Original warning:
src/logfunc.hpp:147:30: error: 'template<class> 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
src/logfunc.hpp

index c6883fc..fd0f4e0 100644 (file)
@@ -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&)
 
index 56b1814..865b9bb 100644 (file)
@@ -34,6 +34,23 @@ on this file might be covered by the GNU General Public License.
 #include <exception>
 #include <stdexcept>
 
+/*
+** 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 <memory>
+#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 <boost/shared_ptr.hpp>
 
 #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