This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug libstdc++/13007] basic_streambuf::pubimbue, imbue wrong
- From: "peturr02 at ru dot is" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 12 Nov 2003 08:09:59 -0000
- Subject: [Bug libstdc++/13007] basic_streambuf::pubimbue, imbue wrong
- References: <20031111103422.13007.peturr02@ru.is>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Additional Comments From peturr02 at ru dot is 2003-11-12 08:09 -------
This bit is wrong:
{
locale __tmp(this->getloc());
this->imbue(__loc);
+ if (__tmp != __loc)
+ _M_buf_locale = __loc;
return __tmp;
}
Consider an implementation of imbue that caches a facet:
class Foo : public streambuf {
ctype<char>* ct;
void imbue(const locale& loc) {
ct = &use_facet<ctype<char> >(loc);
}
};
This is then called like this:
Foo foo;
foo.pubimbue(locale("is_IS"));
foo.pubimbue(locale("is_IS"));
In the first call to pubimbue the locale is set correctly and all is well.
In the second call the temporary object is passed to imbue and a reference
to the facet stored, but streambuf does not store a copy of the temporary
and so the cached facet becomes a dangling pointer.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13007