Details

[Home]

Issue of the Implementation # S0744

Brief

locale::name confuses locale names for LC_TIME and LC_COLLATE categories

Detailed Description

When named locale (locale::name() returns not "*") is heterogeneous, i.e. consists of categories from different locales, locale::name returns string like "CAT1=name1;CAT2=name2;...;CATN=nameN", where CAT1...CATN - categories(LC_CTYPE, LC_NUMERIC...), and name1...nameN - names of locales, from which these categories are taken.


However, names of locales for LC_TIME and LC_COLLATE categories are wrong in this case: locale name for LC_TIME is that for LC_COLLATE and vice versa.

If one create another locale using name of this one, then locale semantic of categories LC_TIME and LC_COLLATE in locale created will be differ from the initial locale.


In the example below, substring "LC_COLLATE=C" is looking for in the locale name. This substring means, that LC_COLLATE category is taken from "C" locale. However, according to the way of locale creation, this category should be taken from another locale (and it is indeed taken from another locale).

Problem location(s) in the standard

Linux Standard Base C++ Specification 3.2, Chapter 9. Libraries, 9.1. Interfaces for libstdcxx that refers ISO/IEC 14882: 2003 Programming languages --C++, section 22.1.1.3

Example

#include <locale>
#include <iostream>
using namespace std;

int main()
{
    //instead "en_US" any locale name may be used, except "C" and "POSIX"
    locale loc(locale("C"), "en_US", locale::collate);
    cout << "Name of locale is " << loc.name() << endl;
    if(loc.name().find("LC_COLLATE=C") != string::npos)
        cout << "Collate facet is taken from \"C\" locale\n";
    return 0;
}

Component

libstdc++

References

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29217

Status

Fixed in gcc-4.2

[Home]