<wchar.h>: Define __CORRECT_ISO_CPP_WCHAR_H_PROTO for Clang [BZ #34692]

Message ID 20260929224014.12925-1-lnicoara@thinkoid.org (mailing list archive)
State Committed
Commit ee64207a98170d25a721faac2384b279192a8b4c
Headers
Series <wchar.h>: Define __CORRECT_ISO_CPP_WCHAR_H_PROTO for Clang [BZ #34692] |

Checks

Context Check Description
redhat-pt-bot/TryBot-apply_patch success Patch applied to master at the time it was sent
linaro-tcwg-bot/tcwg_glibc_build--master-aarch64 success Build passed
redhat-pt-bot/TryBot-32bit success Build for i686
linaro-tcwg-bot/tcwg_glibc_build--master-arm success Build passed
linaro-tcwg-bot/tcwg_glibc_check--master-aarch64 success Test passed
linaro-tcwg-bot/tcwg_glibc_check--master-arm success Test passed

Commit Message

Liviu Nicoara Sept. 29, 2026, 10:40 p.m. UTC
  Without the asm redirects, wcschr et al. are not const-correct.

Commit 953ceff17a4a15b10cfdd5edc3c8cae4884c8ec3 widened the guard of
__CORRECT_ISO_CPP_STRING_H_PROTO in <string.h> to Clang 3.5 and later
[BZ #25232].  <wchar.h> kept the guard it had since 2009, so under
Clang with libstdc++ or with just the C headers, wcschr, wcspbrk,
wcsrchr, wcsstr, wcswcs and wmemchr have only the C prototype.  A
const wchar_t * argument then yields a wchar_t * result without a
diagnostic.

This change applies the <string.h> condition to <wchar.h>.  It does
not impact GCC.

Checked on x86_64-linux-gnu with GCC 16.2.1 and Clang 22.1.8.

Signed-off-by: Liviu Nicoara <lnicoara@thinkoid.org>
---
 wcsmbs/wchar.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
  

Comments

Adhemerval Zanella Netto Oct. 6, 2026, 7:38 p.m. UTC | #1
On 30/09/26 00:40, Liviu Nicoara wrote:
> Without the asm redirects, wcschr et al. are not const-correct.
> 
> Commit 953ceff17a4a15b10cfdd5edc3c8cae4884c8ec3 widened the guard of
> __CORRECT_ISO_CPP_STRING_H_PROTO in <string.h> to Clang 3.5 and later
> [BZ #25232].  <wchar.h> kept the guard it had since 2009, so under
> Clang with libstdc++ or with just the C headers, wcschr, wcspbrk,
> wcsrchr, wcsstr, wcswcs and wmemchr have only the C prototype.  A
> const wchar_t * argument then yields a wchar_t * result without a
> diagnostic.
> 
> This change applies the <string.h> condition to <wchar.h>.  It does
> not impact GCC.
> 
> Checked on x86_64-linux-gnu with GCC 16.2.1 and Clang 22.1.8.
> 
> Signed-off-by: Liviu Nicoara <lnicoara@thinkoid.org>

LGTM, thanks.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>

> ---
>  wcsmbs/wchar.h | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/wcsmbs/wchar.h b/wcsmbs/wchar.h
> index 4709c210fb..ba5a884a40 100644
> --- a/wcsmbs/wchar.h
> +++ b/wcsmbs/wchar.h
> @@ -65,7 +65,8 @@ typedef __gnuc_va_list va_list;
>  #endif
>  
>  /* Tell the caller that we provide correct C++ prototypes.  */
> -#if defined __cplusplus && __GNUC_PREREQ (4, 4)
> +#if defined __cplusplus && (__GNUC_PREREQ (4, 4) \
> +			    || __glibc_clang_prereq (3, 5))
>  # define __CORRECT_ISO_CPP_WCHAR_H_PROTO
>  #endif
>
  
Adhemerval Zanella Netto Oct. 7, 2026, 12:12 p.m. UTC | #2
On 30/09/26 00:40, Liviu Nicoara wrote:
> Without the asm redirects, wcschr et al. are not const-correct.
> 
> Commit 953ceff17a4a15b10cfdd5edc3c8cae4884c8ec3 widened the guard of
> __CORRECT_ISO_CPP_STRING_H_PROTO in <string.h> to Clang 3.5 and later
> [BZ #25232].  <wchar.h> kept the guard it had since 2009, so under
> Clang with libstdc++ or with just the C headers, wcschr, wcspbrk,
> wcsrchr, wcsstr, wcswcs and wmemchr have only the C prototype.  A
> const wchar_t * argument then yields a wchar_t * result without a
> diagnostic.
> 
> This change applies the <string.h> condition to <wchar.h>.  It does
> not impact GCC.
> 
> Checked on x86_64-linux-gnu with GCC 16.2.1 and Clang 22.1.8.
> 
> Signed-off-by: Liviu Nicoara <lnicoara@thinkoid.org>

LGTM, thanks.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
> ---
>  wcsmbs/wchar.h | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/wcsmbs/wchar.h b/wcsmbs/wchar.h
> index 4709c210fb..ba5a884a40 100644
> --- a/wcsmbs/wchar.h
> +++ b/wcsmbs/wchar.h
> @@ -65,7 +65,8 @@ typedef __gnuc_va_list va_list;
>  #endif
>  
>  /* Tell the caller that we provide correct C++ prototypes.  */
> -#if defined __cplusplus && __GNUC_PREREQ (4, 4)
> +#if defined __cplusplus && (__GNUC_PREREQ (4, 4) \
> +			    || __glibc_clang_prereq (3, 5))
>  # define __CORRECT_ISO_CPP_WCHAR_H_PROTO
>  #endif
>
  

Patch

diff --git a/wcsmbs/wchar.h b/wcsmbs/wchar.h
index 4709c210fb..ba5a884a40 100644
--- a/wcsmbs/wchar.h
+++ b/wcsmbs/wchar.h
@@ -65,7 +65,8 @@  typedef __gnuc_va_list va_list;
 #endif
 
 /* Tell the caller that we provide correct C++ prototypes.  */
-#if defined __cplusplus && __GNUC_PREREQ (4, 4)
+#if defined __cplusplus && (__GNUC_PREREQ (4, 4) \
+			    || __glibc_clang_prereq (3, 5))
 # define __CORRECT_ISO_CPP_WCHAR_H_PROTO
 #endif