Fix Werrors with GCC-14.1.0
[platform/upstream/libzypp.git] / zypp / base / Exception.cc
index dfd62e3..e6341f5 100644 (file)
 #include <iostream>
 #include <sstream>
 
-#include "zypp/base/Logger.h"
-#include "zypp/base/LogTools.h"
-#include "zypp/base/Gettext.h"
-#include "zypp/base/String.h"
-#include "zypp/base/Exception.h"
+#include <zypp/base/Logger.h>
+#include <zypp/base/LogTools.h>
+#include <zypp/base/Gettext.h>
+#include <zypp/base/String.h>
+#include <zypp/base/Exception.h>
 
 using std::endl;
 
@@ -49,6 +49,26 @@ namespace zypp
   : _msg( msg_r )
   {}
 
+  Exception::Exception( std::string && msg_r )
+  : _msg( std::move(msg_r) )
+  {}
+
+  Exception::Exception( const std::string & msg_r, const Exception & history_r )
+  : _msg( msg_r )
+  { remember( history_r ); }
+
+  Exception::Exception( std::string && msg_r, const Exception & history_r )
+  : _msg( std::move(msg_r) )
+  { remember( history_r ); }
+
+  Exception::Exception( const std::string & msg_r, Exception && history_r )
+  : _msg( msg_r )
+  { remember( std::move(history_r) ); }
+
+  Exception::Exception( std::string && msg_r, Exception && history_r )
+  : _msg( std::move(msg_r) )
+  { remember( std::move(history_r) ); }
+
   Exception::~Exception() throw()
   {}
 
@@ -92,11 +112,22 @@ namespace zypp
     }
   }
 
-  void Exception::addHistory( const std::string & msg_r )
+  void Exception::remember( Exception && old_r )
   {
-    _history.push_front( msg_r );
+    if ( &old_r != this ) // no self-remember
+    {
+      History & newh( old_r._history );        // stealing it
+      newh.push_front( old_r.asUserString() );
+      _history.swap( newh );
+    }
   }
 
+  void Exception::addHistory( const std::string & msg_r )
+  { _history.push_front( msg_r ); }
+
+  void Exception::addHistory( std::string && msg_r )
+  { _history.push_front( std::move(msg_r) ); }
+
   std::string Exception::historyAsString() const
   {
     // TranslatorExplanation followed by the list of error messages that lead to this exception
@@ -121,18 +152,25 @@ namespace zypp
   { return str::strerror( errno_r ); }
 
   std::string Exception::strErrno( int errno_r, const std::string & msg_r )
+  { return strErrno( errno_r, std::string(msg_r) );  }
+
+  std::string Exception::strErrno( int errno_r, std::string && msg_r )
   {
-    std::string ret( msg_r );
-    ret += ": ";
-    return ret += strErrno( errno_r );
+    msg_r += ": ";
+    return msg_r += strErrno( errno_r );
   }
 
   void Exception::log( const Exception & excpt_r, const CodeLocation & where_r,
                        const char *const prefix_r )
   {
-    INT << where_r << " " << prefix_r << " " << excpt_r << endl;
+    INT << where_r << " " << prefix_r << " " << excpt_r.asUserHistory() << endl;
   }
 
+  void Exception::log( const char * typename_r, const CodeLocation & where_r,
+                       const char *const prefix_r )
+  {
+    INT << where_r << " " << prefix_r << " exception of type " << typename_r << endl;
+  }
   /////////////////////////////////////////////////////////////////
 } // namespace zypp
 ///////////////////////////////////////////////////////////////////