Note: This is a beta release of Red Hat Bugzilla 5.0. The data contained within is a snapshot of the live data so any changes you make will not be reflected in the production Bugzilla. Also email is disabled so feel free to test any aspect of the site that you want. File any problems you find or give feedback here.
Bug 79241 - std::locale constructor does not check environment
Summary: std::locale constructor does not check environment
Keywords:
Status: CLOSED UPSTREAM
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: libstdc++
Version: 8.0
Hardware: i686
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact:
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2002-12-08 11:17 UTC by Need Real Name
Modified: 2007-04-18 16:48 UTC (History)
1 user (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2004-10-01 14:59:46 UTC


Attachments (Terms of Use)

Description Need Real Name 2002-12-08 11:18:00 UTC
Description of Problem:
A std::locale constructed with an empty string ("") does not give the same 
results as calling setlocale(LC_ALL, "").

man setlocale says:

 If locale is "", each part of the locale that should be modified is set
 according  to the environment variables. The details are implementation
 dependent.  For glibc, first (regardless of category), the  environment
 variable  LC_ALL  is  inspected, next the environment variable with the
 same name as the category (LC_COLLATE, LC_CTYPE, LC_MESSAGES,
 LC_MONETARY,  LC_NUMERIC,  LC_TIME) and finally the environment variable LANG.

The same should apply to std::locale, that is, if LC_ALL is set,
 std::locale loc ("");
should be equivalent to
 std::locale loc (getenv("LC_ALL"));
but it appears to work as
 std::locale loc ("C");

Version-Release number of selected component (if applicable):
libstdc++-3.2-7.i386.rpm

How Reproducible:
Always

Steps to Reproduce:
This program demonstrates the problem:

#include <cstdlib>
#include <string>
#include <locale>
#include <cassert>
#include <cstdio>
#include <sstream>
#include <iomanip>
using namespace std;

int main(int argc, char** argv)
{
	clearenv();

	ostringstream stream;
	stream << fixed << setprecision(1);

	stream << 3.5;
	assert(stream.str() == "3.5");

	stream.str("");
	stream.clear();
	stream.imbue(locale("is_IS"));
	stream << 3.5;
	assert(stream.str() == "3,5");

	if (setenv("LC_ALL", "is_IS", true) || setenv("LANG", "is_IS", true))
	{
		perror(argv[0]);
		return -1;
	}

	stream.str("");
	stream.clear();
	stream.imbue(locale(""));
	stream << 3.5;
	assert(stream.str() == "3,5"); // Fails, stream.str() == "3.5"

	return 0;
}

Actual Results:


Expected Results:


Additional Information:

Comment 1 Benjamin Kosnik 2004-10-01 14:59:46 UTC
Fixed in 3.3/3.4 toolchains. Ie, FC1/FC2/RHEL 3/ RHEL 4.

-benjamin



Note You need to log in before you can comment on or make changes to this bug.