public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/108323] New: combine does not change the locale name
@ 2023-01-07  0:37 liweifriends at gmail dot com
  2023-01-07  2:03 ` [Bug libstdc++/108323] " redi at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: liweifriends at gmail dot com @ 2023-01-07  0:37 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108323

            Bug ID: 108323
           Summary: combine does not change the locale name
           Product: gcc
           Version: 12.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: liweifriends at gmail dot com
  Target Milestone: ---

for the following code
```
#include <iostream>
#include <locale>

int main()
{
    std::locale loc = std::locale()
        .combine<std::numpunct<char>>(std::locale("en_US.UTF-8"));
    std::cout << loc.name() << '\n';

    std::cout << (std::locale() == loc);

}
```

gcc outputs 'C' and '1' (https://godbolt.org/z/q8fT4oqj3), which seems a bug?
Because locale::combine should return a new and nameless locale.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug libstdc++/108323] combine does not change the locale name
  2023-01-07  0:37 [Bug c++/108323] New: combine does not change the locale name liweifriends at gmail dot com
@ 2023-01-07  2:03 ` redi at gcc dot gnu.org
  2024-01-30 13:29 ` redi at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2023-01-07  2:03 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108323

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2023-01-07

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug libstdc++/108323] combine does not change the locale name
  2023-01-07  0:37 [Bug c++/108323] New: combine does not change the locale name liweifriends at gmail dot com
  2023-01-07  2:03 ` [Bug libstdc++/108323] " redi at gcc dot gnu.org
@ 2024-01-30 13:29 ` redi at gcc dot gnu.org
  2024-02-01 12:50 ` redi at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2024-01-30 13:29 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108323

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|2023-01-07 00:00:00         |2024-1-30

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
This should be fixed at the same time as
https://cplusplus.github.io/LWG/issue2295

And we should also add a static_assert(__is_facet<_Facet>::value, "") for
https://cplusplus.github.io/LWG/issue436

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug libstdc++/108323] combine does not change the locale name
  2023-01-07  0:37 [Bug c++/108323] New: combine does not change the locale name liweifriends at gmail dot com
  2023-01-07  2:03 ` [Bug libstdc++/108323] " redi at gcc dot gnu.org
  2024-01-30 13:29 ` redi at gcc dot gnu.org
@ 2024-02-01 12:50 ` redi at gcc dot gnu.org
  2024-02-01 12:51 ` redi at gcc dot gnu.org
  2024-05-22 22:33 ` cvs-commit at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2024-02-01 12:50 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108323

Jonathan Wakely <redi at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|2024-01-30 00:00:00         |2024-2-1

--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Kinda related, the implementation of locale::combine uses _M_replace_facet
which seems to have a bug:

  void
  locale::_Impl::
  _M_replace_facet(const _Impl* __imp, const locale::id* __idp)
  {
    size_t __index = __idp->_M_id();
    if ((__index > (__imp->_M_facets_size - 1))
        || !__imp->_M_facets[__index])
      __throw_runtime_error(__N("locale::_Impl::_M_replace_facet"));
    _M_install_facet(__idp, __imp->_M_facets[__index]);
  }

This only checks that a facet with the specified id is present. This is not
sufficient, because it could be a different derived type that has the same id.

e.g.

struct custom_ctype : ctype<char> { ... };
auto loc = std::locale().combine<custom_ctype>(std::locale());

This should throw std::runtime_error because has_facet<custom_ctype> is false.

For combine, _M_replace_facet should use std::has_facet as specified in the
standard. I haven't checked if that would be correct for the other uses of
_M_replace_facet.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug libstdc++/108323] combine does not change the locale name
  2023-01-07  0:37 [Bug c++/108323] New: combine does not change the locale name liweifriends at gmail dot com
                   ` (2 preceding siblings ...)
  2024-02-01 12:50 ` redi at gcc dot gnu.org
@ 2024-02-01 12:51 ` redi at gcc dot gnu.org
  2024-05-22 22:33 ` cvs-commit at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: redi at gcc dot gnu.org @ 2024-02-01 12:51 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108323

--- Comment #3 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Also, locale::combine (and has_facet and use_facet, and locale::global and
locale::classic) should use [[nodiscard]].

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug libstdc++/108323] combine does not change the locale name
  2023-01-07  0:37 [Bug c++/108323] New: combine does not change the locale name liweifriends at gmail dot com
                   ` (3 preceding siblings ...)
  2024-02-01 12:51 ` redi at gcc dot gnu.org
@ 2024-05-22 22:33 ` cvs-commit at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-05-22 22:33 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108323

--- Comment #4 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jonathan Wakely <redi@gcc.gnu.org>:

https://gcc.gnu.org/g:947a9c801e818f412ad4c669a49297c3512b3a6e

commit r15-781-g947a9c801e818f412ad4c669a49297c3512b3a6e
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Tue Jan 30 14:48:28 2024 +0000

    libstdc++: Fix effects of combining locales [PR108323]

    This fixes a bug in locale::combine where we fail to meet the standard's
    requirement that the result is unnamed. It also implements two library
    issues related to the names of combined locales (2295 and 3676).

    libstdc++-v3/ChangeLog:

            PR libstdc++/108323
            * include/bits/locale_classes.tcc (locale(const locale&, Facet*)):
            Return a copy of the first argument when the facet pointer is
            null, as per LWG 2295.
            (locale::combine): Ensure the result is unnamed.
            * src/c++11/localename.cc (_M_replace_categories): Ignore
            whether the second locale has a name when cat == none, as per
            LWG 3676.
            * src/c++98/locale.cc (_M_install_facet): Use __builtin_expect
            to predict that the facet pointer is non-null.
            * testsuite/22_locale/locale/cons/names.cc: New test.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-05-22 22:33 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-01-07  0:37 [Bug c++/108323] New: combine does not change the locale name liweifriends at gmail dot com
2023-01-07  2:03 ` [Bug libstdc++/108323] " redi at gcc dot gnu.org
2024-01-30 13:29 ` redi at gcc dot gnu.org
2024-02-01 12:50 ` redi at gcc dot gnu.org
2024-02-01 12:51 ` redi at gcc dot gnu.org
2024-05-22 22:33 ` cvs-commit at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).