13007 – basic_streambuf::pubimbue, imbue wrong (original) (raw)
Description Pétur Runólfsson 2003-11-11 10:34:23 UTC
Currently, basic_streambuf::pubimbue does not modify _M_buf_locale, but basic_streambuf::imbue does so. This appears wrong.
The effects clause of imbue says "Does nothing"
The postcondition clause of pubimbue(loc) is "loc == getloc()". There is no mention that derived classes need to call basic_streambuf::imbue() from overridden versions for this to hold.
The returns clause of getloc() says that if getloc() is called from an overridden version of imbue, then getloc() will return the previously imbued locale. There is no mention that this does not hold if basic_streambuf::imbue is called from the derived class version.
Comment 3 Paolo Carlini 2003-11-11 13:23:56 UTC
Hi, thanks for the PR and the detailed testcase (will be properly acknowledged!)
Could you please have a look to the attached draft patch?
(Passes testsuite + imbuebug4.cc of course)
Thanks, Paolo.
Comment 4 Pétur Runólfsson 2003-11-12 08:09:56 UTC
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* ct; void imbue(const locale& loc) { ct = &use_facet<ctype >(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.
Comment 5 Paolo Carlini 2003-11-12 09:44:25 UTC
I see... Will change those two lines with a plain "_M_buf_locale = __loc;"
Thanks! Paolo.
Comment 7 Paolo Carlini 2003-11-13 23:16:23 UTC
Fixed for 3.4.
Comment 8 Benjamin Kosnik 2003-12-19 20:33:53 UTC
Yo folks, we should move this patch to the gcc-3_3-branch. Thoughts?
-benjamin
Comment 10 Paolo Carlini 2004-01-07 11:58:39 UTC
Fixed for 3.3.3 too!
Comment 11 Benjamin Kosnik 2004-01-07 16:13:37 UTC
Subject: Re: basic_streambuf::pubimbue, imbue wrong
Fixed for 3.3.3 too!
Thanks Paolo!
-benjamin