Details

[Home]

Issue of the Implementation # S0781

Brief

locale(const char* std_name) can create invalid facets for nonuniform locale

Detailed Description

Constructor locale(const char* std_name), when called with name of nonuniform locale (like "LC_CTYPE=...;LC_COLLATE=...;..."), can create locale with incorrect content of some its facets: these facets differ from facets of locale, created via locale(const locale& other, const char* std_name, category) with subsequent replacing of categories. While this locale has same name as argument of locale(const char* std_name).

This behaviour contradicts description of member-function name() (22.1.1.3, p5):
If *this has a name, then locale(name().c_str()) is equivalent to *this.

Example below demonstrates contradiction of this statement on curr_symbol() property of moneypunct<wchar_t> facet.

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()
{
    locale loc(locale("C"), "en_GB.utf8", locale::monetary);
    const moneypunct<wchar_t>& mp
        = use_facet<moneypunct<wchar_t> >(loc);
    wcout << "curr_symbol is '"
        << mp.curr_symbol() << "'\n";

    locale loc_copy(loc.name().c_str());
    const moneypunct<wchar_t>& mp_copy
        = use_facet<moneypunct<wchar_t> >(loc_copy);
    wcout << "curr_symbol in copy is '"
        << mp_copy.curr_symbol() << "'\n";
    
    if(mp.curr_symbol() != mp_copy.curr_symbol())
        wcout << "Copy is differ from original locale.\n";
    
    return 0;
}

Component

libstdc++

Accepted

GCC Bugzilla 40184

Status

Fixed in CVS

[Home]