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 (tiny change) + + Add 'autosprintf::operator='. Needed because destructor + is not trivial. + Reported at + * 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 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 , 2002. This program is free software: you can redistribute it and/or modify @@ -30,6 +30,13 @@ #include #include "lib-asprintf.h" +/* std::swap() is in since C++11. */ +#if __cplusplus >= 201103L +# include +#else +# include +#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. */