libstdc++/9322: return value of basic_streambuf<>::getloc affected by locale::global

peturr02@ru.is peturr02@ru.is
Wed Jan 15 11:16:00 GMT 2003


>Number:         9322
>Category:       libstdc++
>Synopsis:       return value of basic_streambuf<>::getloc affected by locale::global
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Jan 15 02:56:01 PST 2003
>Closed-Date:
>Last-Modified:
>Originator:     peturr02@ru.is
>Release:        gcc-3.2.1
>Organization:
>Environment:
Red Hat Linux 8.0
>Description:
If basic_streambuf<>::pubimbue() has not been called, the value returned by basic_streambuf<>::getloc() is the current global locale at the time getloc() is called, not the current global locale at the time of construction.

In particular, this means that it is not possible to cache the results of use_facet<>(getloc()), as the lifetime of the locale returned by getloc() is unknown.
>How-To-Repeat:
See attachment.
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: text/plain; name="imbuebug.cc"
Content-Disposition: inline; filename="imbuebug.cc"

#include <locale>
#include <streambuf>

using namespace std;

class Mybuf : public streambuf
{
};

#undef NDEBUG
#include <cassert>

int main()
{
	Mybuf buf;
	locale loc1 = buf.getloc();
	
	locale::global(locale(""));

	locale loc2 = buf.getloc();
	assert(loc1 == loc2);

	return 0;
}



More information about the Gcc-bugs mailing list