[libcxx-commits] [PATCH] D119441: [libc++] Fix locale name construction

Hubert Tong via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Fri Feb 11 23:55:02 PST 2022


hubert.reinterpretcast added a comment.

In D119441#3311394 <https://reviews.llvm.org/D119441#3311394>, @ldionne wrote:

> Thanks for the patch! `locale`s are not my strength, so I left some comment but TBH I don't fully grok why we'd want to make this change. Are we non-conforming at the moment?

Yes, because locales formed from parts of two named locales (that is, C++ locales having names) have names in turn (see C++20 subclause 28.3.1.1 [locale.general] paragraph 8). Locales with names are supposed to compare equal if their names compare equal (see C++20 subclause 28.3.1.5 [locale.operators] paragraph 1). If the implementation wants to give named locales that are formed differently the same name (`*`), then it is required to report that they are equal. It seems an interesting experiment in conforming but unhelpful implementation methods to retain the `*` and correct the equality comparison for conformance, thus we did not propose that direction for this patch.

  #include <locale>
  #include <cassert>
  #include <stdio.h>
  int main(void) {
    std::locale America("en_US.UTF-8");
    std::locale Generic("C");
    fprintf(stderr, "%s\n", America.name().c_str());
    fprintf(stderr, "%s\n", Generic.name().c_str());
  
    std::locale Financial(Generic, America, std::locale::monetary);
    fprintf(stderr, "%s\n", Financial.name().c_str());
  
    std::locale Ascii(America, Generic, std::locale::collate | std::locale::ctype);
    fprintf(stderr, "%s\n", Ascii.name().c_str());
  
    assert((Financial.name() == Ascii.name()) == (Financial == Ascii));
  }

Compiler Explorer link: https://godbolt.org/z/vKj9qMMT4


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D119441/new/

https://reviews.llvm.org/D119441



More information about the libcxx-commits mailing list