Daiki Ueno <[email protected]> writes: 
> But in most cases we need the copy constructor call, no?  I've just
> searched on the Web and several pages says that the self-assignment
> guard can be eliminated when the copy-and-swap idiom is used.  Seems not
> a big deal though.

You are right, thank you for the point.

This patch is better then.

Best regards,
Miguel
diff --git a/gettext-runtime/libasprintf/ChangeLog b/gettext-runtime/libasprintf/ChangeLog
index 9b97cc6..14ae717 100644
--- a/gettext-runtime/libasprintf/ChangeLog
+++ b/gettext-runtime/libasprintf/ChangeLog
@@ -1,3 +1,13 @@
+2013-03-04  Miguel Angel Arruga Vivas  <[email protected]>  (tiny change)
+
+	Add 'autosprintf::operator='. Needed because destructor
+	is not trivial.
+	Reported at <https://savannah.gnu.org/bugs/?33102>
+	* autosprintf.in.h (autosprintf::operator=): New function.
+	Thanks to Daiki Ueno for pointing a better copy-and-swap
+	idiom use.
+	* autosprintf.cc (autosprintf::operator=): Likewise.
+
 2013-01-17  Daiki Ueno  <[email protected]>
 
 	Fix link errors related to C99-style extern inline.
diff --git a/gettext-runtime/libasprintf/autosprintf.cc b/gettext-runtime/libasprintf/autosprintf.cc
index d3639f5..1d3a8f2 100644
--- a/gettext-runtime/libasprintf/autosprintf.cc
+++ b/gettext-runtime/libasprintf/autosprintf.cc
@@ -1,5 +1,5 @@
 /* Class autosprintf - formatted output to an ostream.
-   Copyright (C) 2002 Free Software Foundation, Inc.
+   Copyright (C) 2002, 2013 Free Software Foundation, Inc.
    Written by Bruno Haible <[email protected]>, 2002.
 
    This program is free software: you can redistribute it and/or modify
@@ -30,6 +30,13 @@
 #include <string.h>
 #include "lib-asprintf.h"
 
+/* std::swap() is in <utility> since C++11.  */
+#if __cplusplus >= 201103L
+# include <utility>
+#else
+# include <algorithm>
+#fi
+
 namespace gnu
 {
 
@@ -49,6 +56,13 @@ namespace gnu
     str = (src.str != NULL ? strdup (src.str) : NULL);
   }
 
+  /* Copy constructor.  Necessary because the destructor is nontrivial.  */
+  autosprintf& autosprintf::operator = (autosprintf copy)
+  {
+    std::swap (tmp.str, this->str);
+    return *this;
+  }
+
   /* Destructor: frees the temporarily allocated string.  */
   autosprintf::~autosprintf ()
   {
diff --git a/gettext-runtime/libasprintf/autosprintf.in.h b/gettext-runtime/libasprintf/autosprintf.in.h
index 74f946c..1efd15a 100644
--- a/gettext-runtime/libasprintf/autosprintf.in.h
+++ b/gettext-runtime/libasprintf/autosprintf.in.h
@@ -1,5 +1,5 @@
 /* Class autosprintf - formatted output to an ostream.
-   Copyright (C) 2002, 2012 Free Software Foundation, Inc.
+   Copyright (C) 2002, 2012, 2013 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
@@ -45,6 +45,7 @@ namespace gnu
                 __attribute__ ((__format__ (__printf__, 2, 3)));
     /* Copy constructor.  */
     autosprintf (const autosprintf& src);
+    autosprintf& operator = (autosprintf copy);
     /* Destructor: frees the temporarily allocated string.  */
     ~autosprintf ();
     /* Conversion to string.  */

Reply via email to