Bug 38365 - Locale, constructed from named and unnamed locales, become named
Summary: Locale, constructed from named and unnamed locales, become named
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: libstdc++ (show other bugs)
Version: 4.3.0
: P3 normal
Target Milestone: 4.4.0
Assignee: Paolo Carlini
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-12-02 09:01 UTC by Andrey Tsyvarev
Modified: 2008-12-02 13:34 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2008-12-02 09:53:15


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andrey Tsyvarev 2008-12-02 09:01:01 UTC
Locale constructor

locale(const locale& other, const locale& one, locale::category cats)

creates named locale when 'other' - named locale, but 'one' - unnamed.

According to 22.1.1 p8:
A locale constructed from a name string (such as "POSIX"), or from parts of two named locales, has a name; all others do not.

Example:
[test.cpp]
#include <locale>
#include <iostream>
using namespace std;

int main()
{
    locale other(locale("C"));
    locale one(locale("en_US"), new ctype<char>());
    locale loc(other, one, locale::collate);
    cout << "one.name() is " << one.name() << endl;
    cout << "other.name() is " << other.name() << endl;
    cout << "loc.name() is " << loc.name() << endl;
    return 0;
}

[tester@Fedore8 locale_name]$ g++ test.cpp && ./a.out
one.name() is *
other.name() is C
loc.name() is C
[tester@Fedore8 locale_name]$ g++ --version
g++ (GCC) 4.3.0 20080428 (Red Hat 4.3.0-8)
Copyright (C) 2008 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Comment 1 Paolo Carlini 2008-12-02 09:53:15 UTC
Ok.
Comment 2 paolo@gcc.gnu.org 2008-12-02 10:58:34 UTC
Subject: Bug 38365

Author: paolo
Date: Tue Dec  2 10:57:22 2008
New Revision: 142349

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=142349
Log:
2008-12-02  Paolo Carlini  <paolo.carlini@oracle.com>

	PR libstdc++/38365
	* src/localename.cc (locale::locale(const locale&, const locale&,
	category)): Fix.
	* testsuite/22_locale/locale/cons/38365.cc: New.

Added:
    trunk/libstdc++-v3/testsuite/22_locale/locale/cons/38365.cc
Modified:
    trunk/libstdc++-v3/ChangeLog
    trunk/libstdc++-v3/src/localename.cc

Comment 3 Paolo Carlini 2008-12-02 10:59:06 UTC
Fixed for 4.4.0.
Comment 4 Andrey Tsyvarev 2008-12-02 13:04:45 UTC
According to the code, locale constructor calls

void locale::_Impl::_M_replace_categories(const _Impl* __imp, category __cat)

which already processes names of locales. This function works correctly, when both locales (*this and __impl) have names, or when *this locale hasn't name. But when *this locale has name, but __imp hasn't, the function doesn't clear name of *this.

Your patch fixes the problem at the level of the locale constructor, but why do not fix this problem at the level of  _M_replace_categories() instead? 
Comment 5 Paolo Carlini 2008-12-02 13:21:47 UTC
(In reply to comment #4)
> Your patch fixes the problem at the level of the locale constructor, but why do
> not fix this problem at the level of  _M_replace_categories() instead? 

Because that would not work, _M_impl has already a name ("C") by that time.  Note that all these classes are suboptimal performance-wise, will be redesigned for the next ABI.

Comment 6 Paolo Carlini 2008-12-02 13:34:04 UTC
(In reply to comment #5)
> (In reply to comment #4)
> > Your patch fixes the problem at the level of the locale constructor, but why do
> > not fix this problem at the level of  _M_replace_categories() instead? 
> 
> Because that would not work, _M_impl has already a name ("C") by that time.

Sorry, now I see that the involved _Impl constructor clones, thus creates an unnamed clone if the original one is unnamed, thus the idea can work.
Comment 7 paolo@gcc.gnu.org 2008-12-02 15:04:12 UTC
Subject: Bug 38365

Author: paolo
Date: Tue Dec  2 15:02:53 2008
New Revision: 142358

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=142358
Log:
2008-12-02  Paolo Carlini  <paolo.carlini@oracle.com>

	PR libstdc++/38365 (cont)
	* src/localename.cc (locale::locale(const locale&, const locale&,
	category)): Revert last changes.
	* src/localename.cc (locale::_Impl::_M_replace_categories(const
	_Impl*, category)): Fix here instead; rework.

Modified:
    trunk/libstdc++-v3/ChangeLog
    trunk/libstdc++-v3/src/localename.cc