This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libstdc++/13007] basic_streambuf::pubimbue, imbue wrong


------- 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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]