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.

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

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