+2003-11-13 Paolo Carlini <pcarlini@suse.de>
+ Petur Runolfsson <peturr02@ru.is>
+
+ PR libstdc++/13007
+ * include/bits/fstream.tcc (imbue): Don't touch the stored
+ locale.
+ * include/std/std_streambuf.h (imbue): According to the
+ standard, base class version does nothing.
+ (pubimbue): Store the locale.
+ * testsuite/27_io/basic_filebuf/imbue/char/13007.cc: New.
+ * testsuite/27_io/basic_filebuf/imbue/wchar_t/13007.cc: New.
+ * testsuite/27_io/basic_filebuf/imbue/char/2.cc: Tweak.
+ * testsuite/27_io/basic_filebuf/imbue/wchar_t/2.cc: Likewise.
+ * testsuite/27_io/basic_streambuf/imbue/char/13007-1.cc: New.
+ * testsuite/27_io/basic_streambuf/imbue/char/13007-2.cc: New.
+ * testsuite/27_io/basic_streambuf/imbue/wchar_t/13007-1.cc: New.
+ * testsuite/27_io/basic_streambuf/imbue/wchar_t/13007-2.cc: New.
+
2003-11-13 Petur Runolfsson <peturr02@ru.is>
PR libstdc++/12594
basic_filebuf<_CharT, _Traits>::
imbue(const locale& __loc)
{
- if (this->_M_buf_locale != __loc)
+ if (this->getloc() != __loc)
{
bool __testfail = false;
if (this->is_open())
if (!__testfail)
{
- this->_M_buf_locale = __loc;
if (__builtin_expect(has_facet<__codecvt_type>(__loc), true))
_M_codecvt = &use_facet<__codecvt_type>(__loc);
else
{
locale __tmp(this->getloc());
this->imbue(__loc);
+ _M_buf_locale = __loc;
return __tmp;
}
* are changed by this call. The standard adds, "Between invocations
* of this function a class derived from streambuf can safely cache
* results of calls to locale functions and to members of facets
- * so obtained." This function simply stores the new locale for use
- * by derived classes.
+ * so obtained."
+ *
+ * @note Base class version does nothing.
*/
virtual void
- imbue(const locale& __loc)
- {
- if (_M_buf_locale != __loc)
- _M_buf_locale = __loc;
- }
+ imbue(const locale&)
+ { }
// [27.5.2.4.2] buffer management and positioning
/**
--- /dev/null
+// Copyright (C) 2003 Free Software Foundation, Inc.
+//
+// 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+// 27.8.1.4 Overridden virtual functions
+
+#include <fstream>
+#include <locale>
+#include <testsuite_hooks.h>
+
+class Buf : public std::filebuf
+{
+public:
+ std::locale before;
+ std::locale after;
+
+protected:
+ void imbue(const std::locale& loc)
+ {
+ before = getloc();
+
+ std::filebuf::imbue(loc);
+
+ after = getloc();
+ }
+};
+
+// libstdc++/13007
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ Buf buf;
+ std::locale loc(__gnu_test::try_named_locale("fr_FR"));
+
+ buf.pubimbue(loc);
+
+ VERIFY( buf.getloc() == loc );
+ VERIFY( buf.before == std::locale::classic() );
+ VERIFY( buf.after == std::locale::classic() );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
pos_type p = ob.pubseekoff(2, ios_base::beg, ios_base::in);
VERIFY( p != bad);
- // 1 "if file is not positioned at its beginning" fails...
+ // "if file is not positioned at its beginning" imbue fails
+ // but, according to 27.5.2.2.1, p1, still loc == getloc()
+ // after pubimbue(loc).
locale loc_de = __gnu_test::try_named_locale("de_DE");
locale ret = ob.pubimbue(loc_de);
- VERIFY( ob.getloc() == loc );
+ VERIFY( ob.getloc() == loc_de );
}
int main()
--- /dev/null
+// Copyright (C) 2003 Free Software Foundation, Inc.
+//
+// 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+// 27.8.1.4 Overridden virtual functions
+
+#include <fstream>
+#include <locale>
+#include <testsuite_hooks.h>
+
+class Buf : public std::wfilebuf
+{
+public:
+ std::locale before;
+ std::locale after;
+
+protected:
+ void imbue(const std::locale& loc)
+ {
+ before = getloc();
+
+ std::wfilebuf::imbue(loc);
+
+ after = getloc();
+ }
+};
+
+// libstdc++/13007
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ Buf buf;
+ std::locale loc(__gnu_test::try_named_locale("fr_FR"));
+
+ buf.pubimbue(loc);
+
+ VERIFY( buf.getloc() == loc );
+ VERIFY( buf.before == std::locale::classic() );
+ VERIFY( buf.after == std::locale::classic() );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
pos_type p = ob.pubseekoff(2, ios_base::beg, ios_base::in);
VERIFY( p != bad);
- // 1 "if file is not positioned at its beginning" fails...
+ // "if file is not positioned at its beginning" imbue fails
+ // but, according to 27.5.2.2.1, p1, still loc == getloc()
+ // after pubimbue(loc).
locale loc_de = __gnu_test::try_named_locale("de_DE");
locale ret = ob.pubimbue(loc_de);
- VERIFY( ob.getloc() == loc );
+ VERIFY( ob.getloc() == loc_de );
}
int main()
--- /dev/null
+// Copyright (C) 2003 Free Software Foundation, Inc.
+//
+// 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+// 27.5.2.4.1 Locales
+
+#include <streambuf>
+#include <locale>
+#include <testsuite_hooks.h>
+
+class Buf1 : public std::streambuf
+{
+protected:
+ void imbue(const std::locale&)
+ { }
+};
+
+// libstdc++/13007
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ Buf1 buf;
+ std::locale loc(__gnu_test::try_named_locale("is_IS.UTF-8"));
+
+ buf.pubimbue(loc);
+
+ VERIFY( buf.getloc() == loc );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
--- /dev/null
+// Copyright (C) 2003 Free Software Foundation, Inc.
+//
+// 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+// 27.5.2.4.1 Locales
+
+#include <streambuf>
+#include <locale>
+#include <testsuite_hooks.h>
+
+class Buf2 : public std::streambuf
+{
+public:
+ std::locale before;
+ std::locale after;
+
+protected:
+ void imbue(const std::locale& loc)
+ {
+ before = getloc();
+
+ std::streambuf::imbue(loc);
+
+ after = getloc();
+ }
+};
+
+// libstdc++/13007
+void test02()
+{
+ bool test __attribute__((unused)) = true;
+
+ Buf2 buf;
+ std::locale loc(__gnu_test::try_named_locale("en_US"));
+
+ buf.pubimbue(loc);
+
+ VERIFY( buf.getloc() == loc );
+ VERIFY( buf.before == std::locale::classic() );
+ VERIFY( buf.after == std::locale::classic() );
+}
+
+int main()
+{
+ test02();
+ return 0;
+}
--- /dev/null
+// Copyright (C) 2003 Free Software Foundation, Inc.
+//
+// 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+// 27.5.2.4.1 Locales
+
+#include <streambuf>
+#include <locale>
+#include <testsuite_hooks.h>
+
+class Buf1 : public std::wstreambuf
+{
+protected:
+ void imbue(const std::locale&)
+ { }
+};
+
+// libstdc++/13007
+void test01()
+{
+ bool test __attribute__((unused)) = true;
+
+ Buf1 buf;
+ std::locale loc(__gnu_test::try_named_locale("is_IS.UTF-8"));
+
+ buf.pubimbue(loc);
+
+ VERIFY( buf.getloc() == loc );
+}
+
+int main()
+{
+ test01();
+ return 0;
+}
--- /dev/null
+// Copyright (C) 2003 Free Software Foundation, Inc.
+//
+// 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, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
+// USA.
+
+// 27.5.2.4.1 Locales
+
+#include <streambuf>
+#include <locale>
+#include <testsuite_hooks.h>
+
+class Buf2 : public std::wstreambuf
+{
+public:
+ std::locale before;
+ std::locale after;
+
+protected:
+ void imbue(const std::locale& loc)
+ {
+ before = getloc();
+
+ std::wstreambuf::imbue(loc);
+
+ after = getloc();
+ }
+};
+
+// libstdc++/13007
+void test02()
+{
+ bool test __attribute__((unused)) = true;
+
+ Buf2 buf;
+ std::locale loc(__gnu_test::try_named_locale("en_US"));
+
+ buf.pubimbue(loc);
+
+ VERIFY( buf.getloc() == loc );
+ VERIFY( buf.before == std::locale::classic() );
+ VERIFY( buf.after == std::locale::classic() );
+}
+
+int main()
+{
+ test02();
+ return 0;
+}