Skip to content

[libc++] std::locale(named, unnamed, std::locale::none) should obtain its name from named #144829

@cpplearner

Description

@cpplearner

Reduced from libcxx/test/std/localization/locales/locale/locale.cons/name_construction.pass.cpp:

#include <iostream>
#include <locale>

constexpr auto LOCALE_en_US_UTF_8 = "en_US.UTF-8";
int main(int, char**) {
    std::locale en(LOCALE_en_US_UTF_8);
    std::locale unnamed(std::locale(), new std::ctype<char>);

    {
        std::locale loc(en, unnamed, std::locale::none);
        std::cout << loc.name() << '\n';
    }
  return 0;
}

Both libstdc++ and MSVC's STL print "en_US.UTF-8" for loc.name(), but libc++ prints "*".

I think this can be fixed by swapping the two conditions in build_name.

string build_name(const string& other, const string& one, locale::category c) {
if (other == "*" || one == "*")
return "*";
if (c == locale::none || other == one)
return other;
// FIXME: Handle the more complicated cases, such as when the locale has
// different names for different categories.
return "*";
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    duplicateResolved as duplicatelibc++libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.localeissues related to localization

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions