diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index ee5100f546c..000430fadbe 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,10 @@ +2008-12-02 Paolo Carlini + + PR libstdc++/38365 + * src/localename.cc (locale::locale(const locale&, const locale&, + category)): Fix. + * testsuite/22_locale/locale/cons/38365.cc: New. + 2008-12-01 Benjamin Kosnik PR libstdc++/38080 diff --git a/libstdc++-v3/src/localename.cc b/libstdc++-v3/src/localename.cc index 5394d9a99c6..fe6204b9b49 100644 --- a/libstdc++-v3/src/localename.cc +++ b/libstdc++-v3/src/localename.cc @@ -1,5 +1,5 @@ // Copyright (C) 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, -// 2006, 2007 +// 2006, 2007, 2008 // Free Software Foundation, Inc. // // This file is part of the GNU ISO C++ Library. This library is free @@ -157,7 +157,14 @@ _GLIBCXX_BEGIN_NAMESPACE(std) locale::locale(const locale& __base, const locale& __add, category __cat) : _M_impl(0) - { _M_coalesce(__base, __add, __cat); } + { + _M_coalesce(__base, __add, __cat); + if (!__base._M_impl->_M_names[0] || !__add._M_impl->_M_names[0]) + { + delete [] _M_impl->_M_names[0]; + _M_impl->_M_names[0] = 0; // Unnamed. + } + } void locale::_M_coalesce(const locale& __base, const locale& __add, diff --git a/libstdc++-v3/testsuite/22_locale/locale/cons/38365.cc b/libstdc++-v3/testsuite/22_locale/locale/cons/38365.cc new file mode 100644 index 00000000000..18225941121 --- /dev/null +++ b/libstdc++-v3/testsuite/22_locale/locale/cons/38365.cc @@ -0,0 +1,45 @@ +// { dg-require-namedlocale "" } + +// Copyright (C) 2008 Free Software Foundation +// +// This file is part of the GNU ISO C++ Library. This library is free +// software; you can redistribute it and/or modify it under the +// terms of the GNU General Public License as published by the +// Free Software Foundation; either version 2, or (at your option) +// any later version. + +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License along +// with this library; see the file COPYING. If not, write to the Free +// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +// USA. + +// 22.1.1.2 locale constructors and destructors [lib.locale.cons] + +#include +#include + +// libstdc++/38365 +void test01() +{ + using namespace std; + bool test __attribute__((unused)) = true; + + locale other(locale("C")); + locale one(locale("en_US"), new ctype()); + locale loc(other, one, locale::collate); + + VERIFY( one.name() == "*" ); + VERIFY( other.name() == "C" ); + VERIFY( loc.name() == "*" ); +} + +int main() +{ + test01(); + return 0; +}