re PR libstdc++/13007 (basic_streambuf::pubimbue, imbue wrong)

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.

Co-Authored-By: Petur Runolfsson <peturr02@ru.is>

From-SVN: r73563
This commit is contained in:
Paolo Carlini 2003-11-13 23:13:22 +00:00 committed by Paolo Carlini
parent ab7c6efde0
commit a2dcfada8a
11 changed files with 375 additions and 13 deletions

View File

@ -1,3 +1,21 @@
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

View File

@ -742,7 +742,7 @@ namespace std
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())
@ -758,7 +758,6 @@ namespace std
if (!__testfail)
{
this->_M_buf_locale = __loc;
if (__builtin_expect(has_facet<__codecvt_type>(__loc), true))
_M_codecvt = &use_facet<__codecvt_type>(__loc);
else

View File

@ -200,6 +200,7 @@ namespace std
{
locale __tmp(this->getloc());
this->imbue(__loc);
_M_buf_locale = __loc;
return __tmp;
}
@ -538,15 +539,13 @@ namespace std
* 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
/**

View File

@ -0,0 +1,61 @@
// 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;
}

View File

@ -41,10 +41,12 @@ void test02()
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()

View File

@ -0,0 +1,61 @@
// 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;
}

View File

@ -41,10 +41,12 @@ void test02()
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()

View File

@ -0,0 +1,49 @@
// 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;
}

View File

@ -0,0 +1,61 @@
// 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;
}

View File

@ -0,0 +1,49 @@
// 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;
}

View File

@ -0,0 +1,61 @@
// 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;
}