public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] c++: Enable __has_builtin for new reference binding built-ins
@ 2022-07-19 13:11 Jonathan Wakely
  2022-07-19 13:30 ` Marek Polacek
  2022-07-19 14:05 ` Jason Merrill
  0 siblings, 2 replies; 3+ messages in thread
From: Jonathan Wakely @ 2022-07-19 13:11 UTC (permalink / raw)
  To: libstdc++, gcc-patches; +Cc: Marek Polacek, Jason Merrill

Tested x86_64-linux, OK for trunk?

-- >8 --

The new built-ins need to be detectable using __has_builtin, and the
library should use that to check for them.

This fixes an error with Clang when C++23 is enabled.

gcc/cp/ChangeLog:

	* cp-objcp-common.cc (names_builtin_p): Return true for
	RID_REF_CONSTRUCTS_FROM_TEMPORARY and
	RID_REF_CONVERTS_FROM_TEMPORARY.

libstdc++-v3/ChangeLog:

	* include/std/type_traits (__cpp_lib_reference_from_temporary)
	(reference_constructs_from_temporary)
	(reference_converts_from_temporary): Only define when the
	built-ins are available.
---
 gcc/cp/cp-objcp-common.cc            | 2 ++
 libstdc++-v3/include/std/type_traits | 4 ++++
 2 files changed, 6 insertions(+)

diff --git a/gcc/cp/cp-objcp-common.cc b/gcc/cp/cp-objcp-common.cc
index 0b70d5567e4..4079a4b4aec 100644
--- a/gcc/cp/cp-objcp-common.cc
+++ b/gcc/cp/cp-objcp-common.cc
@@ -461,6 +461,8 @@ names_builtin_p (const char *name)
     case RID_IS_ASSIGNABLE:
     case RID_IS_CONSTRUCTIBLE:
     case RID_UNDERLYING_TYPE:
+    case RID_REF_CONSTRUCTS_FROM_TEMPORARY:
+    case RID_REF_CONVERTS_FROM_TEMPORARY:
       return true;
     default:
       break;
diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits
index b1a1deecf66..14b029cec64 100644
--- a/libstdc++-v3/include/std/type_traits
+++ b/libstdc++-v3/include/std/type_traits
@@ -3505,6 +3505,9 @@ template<typename _Ret, typename _Fn, typename... _Args>
   template<typename _Tp>
     inline constexpr bool is_scoped_enum_v = is_scoped_enum<_Tp>::value;
 
+#if __has_builtin(__reference_constructs_from_temporary) \
+  && __has_builtin(__reference_converts_from_temporary)
+
 #define __cpp_lib_reference_from_temporary 202202L
 
   /// True if _Tp is a reference type, a _Up value can be bound to _Tp in
@@ -3544,6 +3547,7 @@ template<typename _Ret, typename _Fn, typename... _Args>
   template<typename _Tp, typename _Up>
     inline constexpr bool reference_converts_from_temporary_v
       = reference_converts_from_temporary<_Tp, _Up>::value;
+#endif // __has_builtin for reference_from_temporary
 #endif // C++23
 
 #if _GLIBCXX_HAVE_IS_CONSTANT_EVALUATED
-- 
2.34.3


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

* Re: [PATCH] c++: Enable __has_builtin for new reference binding built-ins
  2022-07-19 13:11 [PATCH] c++: Enable __has_builtin for new reference binding built-ins Jonathan Wakely
@ 2022-07-19 13:30 ` Marek Polacek
  2022-07-19 14:05 ` Jason Merrill
  1 sibling, 0 replies; 3+ messages in thread
From: Marek Polacek @ 2022-07-19 13:30 UTC (permalink / raw)
  To: Jonathan Wakely; +Cc: libstdc++, gcc-patches, Jason Merrill

On Tue, Jul 19, 2022 at 02:11:02PM +0100, Jonathan Wakely wrote:
> Tested x86_64-linux, OK for trunk?
> 
> -- >8 --
> 
> The new built-ins need to be detectable using __has_builtin, and the
> library should use that to check for them.
> 
> This fixes an error with Clang when C++23 is enabled.

LGTM but can't approve.

Thanks and sorry for missing this!
 
> gcc/cp/ChangeLog:
> 
> 	* cp-objcp-common.cc (names_builtin_p): Return true for
> 	RID_REF_CONSTRUCTS_FROM_TEMPORARY and
> 	RID_REF_CONVERTS_FROM_TEMPORARY.
> 
> libstdc++-v3/ChangeLog:
> 
> 	* include/std/type_traits (__cpp_lib_reference_from_temporary)
> 	(reference_constructs_from_temporary)
> 	(reference_converts_from_temporary): Only define when the
> 	built-ins are available.
> ---
>  gcc/cp/cp-objcp-common.cc            | 2 ++
>  libstdc++-v3/include/std/type_traits | 4 ++++
>  2 files changed, 6 insertions(+)
> 
> diff --git a/gcc/cp/cp-objcp-common.cc b/gcc/cp/cp-objcp-common.cc
> index 0b70d5567e4..4079a4b4aec 100644
> --- a/gcc/cp/cp-objcp-common.cc
> +++ b/gcc/cp/cp-objcp-common.cc
> @@ -461,6 +461,8 @@ names_builtin_p (const char *name)
>      case RID_IS_ASSIGNABLE:
>      case RID_IS_CONSTRUCTIBLE:
>      case RID_UNDERLYING_TYPE:
> +    case RID_REF_CONSTRUCTS_FROM_TEMPORARY:
> +    case RID_REF_CONVERTS_FROM_TEMPORARY:
>        return true;
>      default:
>        break;
> diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits
> index b1a1deecf66..14b029cec64 100644
> --- a/libstdc++-v3/include/std/type_traits
> +++ b/libstdc++-v3/include/std/type_traits
> @@ -3505,6 +3505,9 @@ template<typename _Ret, typename _Fn, typename... _Args>
>    template<typename _Tp>
>      inline constexpr bool is_scoped_enum_v = is_scoped_enum<_Tp>::value;
>  
> +#if __has_builtin(__reference_constructs_from_temporary) \
> +  && __has_builtin(__reference_converts_from_temporary)
> +
>  #define __cpp_lib_reference_from_temporary 202202L
>  
>    /// True if _Tp is a reference type, a _Up value can be bound to _Tp in
> @@ -3544,6 +3547,7 @@ template<typename _Ret, typename _Fn, typename... _Args>
>    template<typename _Tp, typename _Up>
>      inline constexpr bool reference_converts_from_temporary_v
>        = reference_converts_from_temporary<_Tp, _Up>::value;
> +#endif // __has_builtin for reference_from_temporary
>  #endif // C++23
>  
>  #if _GLIBCXX_HAVE_IS_CONSTANT_EVALUATED
> -- 
> 2.34.3
> 

Marek


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

* Re: [PATCH] c++: Enable __has_builtin for new reference binding built-ins
  2022-07-19 13:11 [PATCH] c++: Enable __has_builtin for new reference binding built-ins Jonathan Wakely
  2022-07-19 13:30 ` Marek Polacek
@ 2022-07-19 14:05 ` Jason Merrill
  1 sibling, 0 replies; 3+ messages in thread
From: Jason Merrill @ 2022-07-19 14:05 UTC (permalink / raw)
  To: Jonathan Wakely, libstdc++, gcc-patches; +Cc: Marek Polacek

On 7/19/22 09:11, Jonathan Wakely wrote:
> Tested x86_64-linux, OK for trunk?

OK.

> -- >8 --
> 
> The new built-ins need to be detectable using __has_builtin, and the
> library should use that to check for them.
> 
> This fixes an error with Clang when C++23 is enabled.
> 
> gcc/cp/ChangeLog:
> 
> 	* cp-objcp-common.cc (names_builtin_p): Return true for
> 	RID_REF_CONSTRUCTS_FROM_TEMPORARY and
> 	RID_REF_CONVERTS_FROM_TEMPORARY.
> 
> libstdc++-v3/ChangeLog:
> 
> 	* include/std/type_traits (__cpp_lib_reference_from_temporary)
> 	(reference_constructs_from_temporary)
> 	(reference_converts_from_temporary): Only define when the
> 	built-ins are available.
> ---
>   gcc/cp/cp-objcp-common.cc            | 2 ++
>   libstdc++-v3/include/std/type_traits | 4 ++++
>   2 files changed, 6 insertions(+)
> 
> diff --git a/gcc/cp/cp-objcp-common.cc b/gcc/cp/cp-objcp-common.cc
> index 0b70d5567e4..4079a4b4aec 100644
> --- a/gcc/cp/cp-objcp-common.cc
> +++ b/gcc/cp/cp-objcp-common.cc
> @@ -461,6 +461,8 @@ names_builtin_p (const char *name)
>       case RID_IS_ASSIGNABLE:
>       case RID_IS_CONSTRUCTIBLE:
>       case RID_UNDERLYING_TYPE:
> +    case RID_REF_CONSTRUCTS_FROM_TEMPORARY:
> +    case RID_REF_CONVERTS_FROM_TEMPORARY:
>         return true;
>       default:
>         break;
> diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits
> index b1a1deecf66..14b029cec64 100644
> --- a/libstdc++-v3/include/std/type_traits
> +++ b/libstdc++-v3/include/std/type_traits
> @@ -3505,6 +3505,9 @@ template<typename _Ret, typename _Fn, typename... _Args>
>     template<typename _Tp>
>       inline constexpr bool is_scoped_enum_v = is_scoped_enum<_Tp>::value;
>   
> +#if __has_builtin(__reference_constructs_from_temporary) \
> +  && __has_builtin(__reference_converts_from_temporary)
> +
>   #define __cpp_lib_reference_from_temporary 202202L
>   
>     /// True if _Tp is a reference type, a _Up value can be bound to _Tp in
> @@ -3544,6 +3547,7 @@ template<typename _Ret, typename _Fn, typename... _Args>
>     template<typename _Tp, typename _Up>
>       inline constexpr bool reference_converts_from_temporary_v
>         = reference_converts_from_temporary<_Tp, _Up>::value;
> +#endif // __has_builtin for reference_from_temporary
>   #endif // C++23
>   
>   #if _GLIBCXX_HAVE_IS_CONSTANT_EVALUATED


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

end of thread, other threads:[~2022-07-19 14:05 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-19 13:11 [PATCH] c++: Enable __has_builtin for new reference binding built-ins Jonathan Wakely
2022-07-19 13:30 ` Marek Polacek
2022-07-19 14:05 ` Jason Merrill

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).