libstdc++: Do not assume existence of char8_t codecvt facet

Message ID LO4P265MB5914451ED93CD4B7617714A0804EA@LO4P265MB5914.GBRP265.PROD.OUTLOOK.COM
State Committed
Headers
Series libstdc++: Do not assume existence of char8_t codecvt facet |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gcc_build--master-arm fail Patch failed to apply
linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 fail Patch failed to apply
linaro-tcwg-bot/tcwg_gcc_check--master-aarch64 pending Test started
linaro-tcwg-bot/tcwg_gcc_check--master-arm pending Test started

Commit Message

Joseph Faulls June 2, 2023, 3:44 p.m. UTC
  It is not required that codecvt<char8_t, char, mbstate_t> facet be supported by
the locale, nor is it added as part of the default locale. This can lead to
dangerous behaviour when static_cast.

libstdc++-v3/ChangeLog:

        * include/bits/locale_classes.tcc: Remove check.
---
libstdc++-v3/include/bits/locale_classes.tcc | 3 ---
1 file changed, 3 deletions(-)

--
2.34.1
  

Comments

Jonathan Wakely June 2, 2023, 4:52 p.m. UTC | #1
On Fri, 2 Jun 2023 at 16:45, Joseph Faulls wrote:

> It is not required that codecvt<char8_t, char, mbstate_t> facet be
> supported by
>
> the locale, nor is it added as part of the default locale. This can lead to
>
> dangerous behaviour when static_cast.
>

Ouch, yes indeed. I don't know why I added that there. Thanks for the
patch, I'll apply it to trunk and gcc-13 ASAP.




>
> libstdc++-v3/ChangeLog:
>
>
>
>         * include/bits/locale_classes.tcc: Remove check.
>
> ---
>
> libstdc++-v3/include/bits/locale_classes.tcc | 3 ---
>
> 1 file changed, 3 deletions(-)
>
>
>
> diff --git a/libstdc++-v3/include/bits/locale_classes.tcc
> b/libstdc++-v3/include/bits/locale_classes.tcc
>
> index 94838cd7796..2351dd5bcfb 100644
>
> --- a/libstdc++-v3/include/bits/locale_classes.tcc
>
> +++ b/libstdc++-v3/include/bits/locale_classes.tcc
>
> @@ -129,9 +129,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>
>        _GLIBCXX_STD_FACET(time_put<wchar_t>);
>
>        _GLIBCXX_STD_FACET(messages<wchar_t>);
>
> #endif
>
> -#ifdef _GLIBCXX_USE_CHAR8_T
>
> -      _GLIBCXX_STD_FACET(codecvt<char8_t, char, mbstate_t>);
>
> -#endif
>
> #if __cplusplus >= 201103L
>
>        _GLIBCXX_STD_FACET(codecvt<char16_t, char, mbstate_t>);
>
>        _GLIBCXX_STD_FACET(codecvt<char32_t, char, mbstate_t>);
>
> --
>
> 2.34.1
>
  
Jonathan Wakely June 6, 2023, 11:45 a.m. UTC | #2
On Fri, 2 Jun 2023 at 17:52, Jonathan Wakely <jwakely@redhat.com> wrote:

> On Fri, 2 Jun 2023 at 16:45, Joseph Faulls wrote:
>
>> It is not required that codecvt<char8_t, char, mbstate_t> facet be
>> supported by
>>
>> the locale, nor is it added as part of the default locale. This can lead
>> to
>>
>> dangerous behaviour when static_cast.
>>
>
> Ouch, yes indeed. I don't know why I added that there. Thanks for the
> patch, I'll apply it to trunk and gcc-13 ASAP.
>

I've pushed it to trunk now. As it's only removing 3 lines I don't think we
need a copyright assignment or DCO sign-off for this patch - thanks for
contributing it.

I think what I intended to check for there was codecvt<char16_t, char8_t,
mbstate_t> and codecvt<char32_t, char8_t, mbstate_t>, but I had a brainfart.


>
>
>
>
>>
>> libstdc++-v3/ChangeLog:
>>
>>
>>
>>         * include/bits/locale_classes.tcc: Remove check.
>>
>> ---
>>
>> libstdc++-v3/include/bits/locale_classes.tcc | 3 ---
>>
>> 1 file changed, 3 deletions(-)
>>
>>
>>
>> diff --git a/libstdc++-v3/include/bits/locale_classes.tcc
>> b/libstdc++-v3/include/bits/locale_classes.tcc
>>
>> index 94838cd7796..2351dd5bcfb 100644
>>
>> --- a/libstdc++-v3/include/bits/locale_classes.tcc
>>
>> +++ b/libstdc++-v3/include/bits/locale_classes.tcc
>>
>> @@ -129,9 +129,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
>>
>>        _GLIBCXX_STD_FACET(time_put<wchar_t>);
>>
>>        _GLIBCXX_STD_FACET(messages<wchar_t>);
>>
>> #endif
>>
>> -#ifdef _GLIBCXX_USE_CHAR8_T
>>
>> -      _GLIBCXX_STD_FACET(codecvt<char8_t, char, mbstate_t>);
>>
>> -#endif
>>
>> #if __cplusplus >= 201103L
>>
>>        _GLIBCXX_STD_FACET(codecvt<char16_t, char, mbstate_t>);
>>
>>        _GLIBCXX_STD_FACET(codecvt<char32_t, char, mbstate_t>);
>>
>> --
>>
>> 2.34.1
>>
>
  

Patch

diff --git a/libstdc++-v3/include/bits/locale_classes.tcc b/libstdc++-v3/include/bits/locale_classes.tcc
index 94838cd7796..2351dd5bcfb 100644
--- a/libstdc++-v3/include/bits/locale_classes.tcc
+++ b/libstdc++-v3/include/bits/locale_classes.tcc
@@ -129,9 +129,6 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
       _GLIBCXX_STD_FACET(time_put<wchar_t>);
       _GLIBCXX_STD_FACET(messages<wchar_t>);
#endif
-#ifdef _GLIBCXX_USE_CHAR8_T
-      _GLIBCXX_STD_FACET(codecvt<char8_t, char, mbstate_t>);
-#endif
#if __cplusplus >= 201103L
       _GLIBCXX_STD_FACET(codecvt<char16_t, char, mbstate_t>);
       _GLIBCXX_STD_FACET(codecvt<char32_t, char, mbstate_t>);