* Question about _GLIBCXX_HAVE_BUILTIN_IS_SAME
@ 2024-02-07 21:58 Ken Matsui
2024-02-08 0:13 ` Jonathan Wakely
0 siblings, 1 reply; 4+ messages in thread
From: Ken Matsui @ 2024-02-07 21:58 UTC (permalink / raw)
To: libstdc++
Hi,
I found we are using _GLIBCXX_HAVE_BUILTIN_IS_SAME in type_traits, but I
think we can use _GLIBCXX_USE_BUILTIN_TRAIT(__is_same) instead. I feel
this is a bit more readable and consistent with other traits. With this
change, AFAIK, _GLIBCXX_HAVE_BUILTIN_IS_SAME is not used anywhere, but
can we completely remove it from gcc/libstdc++-v3/include/bits/c++config
or is there any reason to keep it?
/// is_same
+#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_same)
template<typename _Tp, typename _Up>
struct is_same
-#ifdef _GLIBCXX_HAVE_BUILTIN_IS_SAME
: public __bool_constant<__is_same(_Tp, _Up)>
+ { };
#else
+ template<typename _Tp, typename _Up>
+ struct is_same
: public false_type
-#endif
{ };
-#ifndef _GLIBCXX_HAVE_BUILTIN_IS_SAME
template<typename _Tp>
struct is_same<_Tp, _Tp>
: public true_type
{ };
#endif
I am also wondering if we could replace other _GLIBCXX_HAVE_BUILTIN_*
macros with _GLIBCXX_USE_BUILTIN_TRAIT(*):
* _GLIBCXX_HAVE_BUILTIN_HAS_UNIQ_OBJ_REP
* _GLIBCXX_HAVE_BUILTIN_IS_AGGREGATE
* _GLIBCXX_HAVE_BUILTIN_LAUNDER
--
Ken Matsui
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Question about _GLIBCXX_HAVE_BUILTIN_IS_SAME
2024-02-07 21:58 Question about _GLIBCXX_HAVE_BUILTIN_IS_SAME Ken Matsui
@ 2024-02-08 0:13 ` Jonathan Wakely
2024-02-09 19:35 ` Ken Matsui
0 siblings, 1 reply; 4+ messages in thread
From: Jonathan Wakely @ 2024-02-08 0:13 UTC (permalink / raw)
To: Ken Matsui; +Cc: libstdc++
[-- Attachment #1: Type: text/plain, Size: 2343 bytes --]
On Wed, 7 Feb 2024 at 21:59, Ken Matsui <kmatsui@cs.washington.edu> wrote:
> Hi,
>
> I found we are using _GLIBCXX_HAVE_BUILTIN_IS_SAME in type_traits, but I
> think we can use _GLIBCXX_USE_BUILTIN_TRAIT(__is_same) instead. I feel
> this is a bit more readable and consistent with other traits. With this
>
Agreed.
> change, AFAIK, _GLIBCXX_HAVE_BUILTIN_IS_SAME is not used anywhere, but
> can we completely remove it from gcc/libstdc++-v3/include/bits/c++config
> or is there any reason to keep it?
>
No, it can go.
The reason we have that macro is historical. Originally, gcc did not define
__is_same, only __is_same_as. Clang defined __is_same. So we needed to use
a different built-in depending which compiler we were using.
Since https://gcc.gnu.org/g:73ae6eb57251 we just use __is_same for both GCC
and Clang (and Intel). We can simplify it as you suggest.
>
> /// is_same
> +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_same)
> template<typename _Tp, typename _Up>
> struct is_same
> -#ifdef _GLIBCXX_HAVE_BUILTIN_IS_SAME
> : public __bool_constant<__is_same(_Tp, _Up)>
> + { };
> #else
> + template<typename _Tp, typename _Up>
> + struct is_same
> : public false_type
> -#endif
> { };
>
> -#ifndef _GLIBCXX_HAVE_BUILTIN_IS_SAME
> template<typename _Tp>
> struct is_same<_Tp, _Tp>
> : public true_type
> { };
> #endif
>
> I am also wondering if we could replace other _GLIBCXX_HAVE_BUILTIN_*
> macros with _GLIBCXX_USE_BUILTIN_TRAIT(*):
>
> * _GLIBCXX_HAVE_BUILTIN_HAS_UNIQ_OBJ_REP
> * _GLIBCXX_HAVE_BUILTIN_IS_AGGREGATE
> * _GLIBCXX_HAVE_BUILTIN_LAUNDER
>
Yes, let's normalize all of these to use the new form.
At some point we should also simplify this:
#ifdef __has_builtin
# ifdef __is_identifier
// Intel and older Clang require !__is_identifier for some built-ins:
# define _GLIBCXX_HAS_BUILTIN(B) __has_builtin(B) || ! __is_identifier(B)
# else
# define _GLIBCXX_HAS_BUILTIN(B) __has_builtin(B)
# endif
#endif
I think we can stop supporting old versions of Clang where
__is_builtin(__is_same) is false, but we should verify which version of
Clang stopped requiring !__is_identifier for those built-ins. If it's older
than Clang 14 we can remove _GLIBCXX_HAS_BUILTIN and just use __has_builtin
directly in _GLIBCXX_USE_BUILTIN_TRAIT. That should wait for GCC 15 though.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Question about _GLIBCXX_HAVE_BUILTIN_IS_SAME
2024-02-08 0:13 ` Jonathan Wakely
@ 2024-02-09 19:35 ` Ken Matsui
2024-02-13 23:34 ` Ken Matsui
0 siblings, 1 reply; 4+ messages in thread
From: Ken Matsui @ 2024-02-09 19:35 UTC (permalink / raw)
To: Jonathan Wakely; +Cc: libstdc++
On Wed, 07 Feb 2024 at 16:13, Jonathan Wakely <jwakely@redhat.com> wrote:
>
>
> On Wed, 7 Feb 2024 at 21:59, Ken Matsui <kmatsui@cs.washington.edu> wrote:
>
> Hi,
>
> I found we are using _GLIBCXX_HAVE_BUILTIN_IS_SAME in type_traits, but I
> think we can use _GLIBCXX_USE_BUILTIN_TRAIT(__is_same) instead. I feel
> this is a bit more readable and consistent with other traits. With this
>
>
> Agreed.
>
>
> change, AFAIK, _GLIBCXX_HAVE_BUILTIN_IS_SAME is not used anywhere, but
> can we completely remove it from gcc/libstdc++-v3/include/bits/c++config
> or is there any reason to keep it?
>
>
> No, it can go.
>
> The reason we have that macro is historical. Originally, gcc did not define
> __is_same, only __is_same_as. Clang defined __is_same. So we needed to use a
> different built-in depending which compiler we were using.
>
> Since https://gcc.gnu.org/g:73ae6eb57251 we just use __is_same for both GCC and
> Clang (and Intel). We can simplify it as you suggest.
>
>
>
>
> /// is_same
> +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_same)
> template<typename _Tp, typename _Up>
> struct is_same
> -#ifdef _GLIBCXX_HAVE_BUILTIN_IS_SAME
> : public __bool_constant<__is_same(_Tp, _Up)>
> + { };
> #else
> + template<typename _Tp, typename _Up>
> + struct is_same
> : public false_type
> -#endif
> { };
>
> -#ifndef _GLIBCXX_HAVE_BUILTIN_IS_SAME
> template<typename _Tp>
> struct is_same<_Tp, _Tp>
> : public true_type
> { };
> #endif
>
> I am also wondering if we could replace other _GLIBCXX_HAVE_BUILTIN_*
> macros with _GLIBCXX_USE_BUILTIN_TRAIT(*):
>
> * _GLIBCXX_HAVE_BUILTIN_HAS_UNIQ_OBJ_REP
> * _GLIBCXX_HAVE_BUILTIN_IS_AGGREGATE
> * _GLIBCXX_HAVE_BUILTIN_LAUNDER
>
>
> Yes, let's normalize all of these to use the new form.
>
It seems that these macros are used for feature test macros. I think
it does not make sense to use _GLIBCXX_USE_BUILTIN_TRAIT for them IIUC.
Or do you think we can replace them with _GLIBCXX_USE_BUILTIN_TRAIT?
#if !defined(__cpp_lib_launder)
# if (__cplusplus >= 201703L) && (defined(_GLIBCXX_HAVE_BUILTIN_LAUNDER))
# define __glibcxx_launder 201606L
# if defined(__glibcxx_want_all) || defined(__glibcxx_want_launder)
# define __cpp_lib_launder 201606L
# endif
# endif
#endif /* !defined(__cpp_lib_launder) && defined(__glibcxx_want_launder) */
#undef __glibcxx_want_launder
> At some point we should also simplify this:
>
> #ifdef __has_builtin
> # ifdef __is_identifier
> // Intel and older Clang require !__is_identifier for some built-ins:
> # define _GLIBCXX_HAS_BUILTIN(B) __has_builtin(B) || ! __is_identifier(B)
> # else
> # define _GLIBCXX_HAS_BUILTIN(B) __has_builtin(B)
> # endif
> #endif
>
> I think we can stop supporting old versions of Clang where __is_builtin
> (__is_same) is false, but we should verify which version of Clang stopped
> requiring !__is_identifier for those built-ins. If it's older than Clang 14 we
> can remove _GLIBCXX_HAS_BUILTIN and just use __has_builtin directly in
> _GLIBCXX_USE_BUILTIN_TRAIT. That should wait for GCC 15 though.
>
>
>
>
>
--
Ken Matsui
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Question about _GLIBCXX_HAVE_BUILTIN_IS_SAME
2024-02-09 19:35 ` Ken Matsui
@ 2024-02-13 23:34 ` Ken Matsui
0 siblings, 0 replies; 4+ messages in thread
From: Ken Matsui @ 2024-02-13 23:34 UTC (permalink / raw)
To: Jonathan Wakely; +Cc: libstdc++
On Fri, Feb 9, 2024 at 11:35 AM Ken Matsui <kmatsui@cs.washington.edu> wrote:
>
> On Wed, 07 Feb 2024 at 16:13, Jonathan Wakely <jwakely@redhat.com> wrote:
> >
> >
> > On Wed, 7 Feb 2024 at 21:59, Ken Matsui <kmatsui@cs.washington.edu> wrote:
> >
> > Hi,
> >
> > I found we are using _GLIBCXX_HAVE_BUILTIN_IS_SAME in type_traits, but I
> > think we can use _GLIBCXX_USE_BUILTIN_TRAIT(__is_same) instead. I feel
> > this is a bit more readable and consistent with other traits. With this
> >
> >
> > Agreed.
> >
> >
> > change, AFAIK, _GLIBCXX_HAVE_BUILTIN_IS_SAME is not used anywhere, but
> > can we completely remove it from gcc/libstdc++-v3/include/bits/c++config
> > or is there any reason to keep it?
> >
> >
> > No, it can go.
> >
> > The reason we have that macro is historical. Originally, gcc did not define
> > __is_same, only __is_same_as. Clang defined __is_same. So we needed to use a
> > different built-in depending which compiler we were using.
> >
> > Since https://gcc.gnu.org/g:73ae6eb57251 we just use __is_same for both GCC and
> > Clang (and Intel). We can simplify it as you suggest.
> >
> >
> >
> >
> > /// is_same
> > +#if _GLIBCXX_USE_BUILTIN_TRAIT(__is_same)
> > template<typename _Tp, typename _Up>
> > struct is_same
> > -#ifdef _GLIBCXX_HAVE_BUILTIN_IS_SAME
> > : public __bool_constant<__is_same(_Tp, _Up)>
> > + { };
> > #else
> > + template<typename _Tp, typename _Up>
> > + struct is_same
> > : public false_type
> > -#endif
> > { };
> >
> > -#ifndef _GLIBCXX_HAVE_BUILTIN_IS_SAME
> > template<typename _Tp>
> > struct is_same<_Tp, _Tp>
> > : public true_type
> > { };
> > #endif
> >
> > I am also wondering if we could replace other _GLIBCXX_HAVE_BUILTIN_*
> > macros with _GLIBCXX_USE_BUILTIN_TRAIT(*):
> >
> > * _GLIBCXX_HAVE_BUILTIN_HAS_UNIQ_OBJ_REP
> > * _GLIBCXX_HAVE_BUILTIN_IS_AGGREGATE
> > * _GLIBCXX_HAVE_BUILTIN_LAUNDER
> >
> >
> > Yes, let's normalize all of these to use the new form.
> >
>
> It seems that these macros are used for feature test macros. I think
> it does not make sense to use _GLIBCXX_USE_BUILTIN_TRAIT for them IIUC.
> Or do you think we can replace them with _GLIBCXX_USE_BUILTIN_TRAIT?
>
> #if !defined(__cpp_lib_launder)
> # if (__cplusplus >= 201703L) && (defined(_GLIBCXX_HAVE_BUILTIN_LAUNDER))
> # define __glibcxx_launder 201606L
> # if defined(__glibcxx_want_all) || defined(__glibcxx_want_launder)
> # define __cpp_lib_launder 201606L
> # endif
> # endif
> #endif /* !defined(__cpp_lib_launder) && defined(__glibcxx_want_launder) */
> #undef __glibcxx_want_launder
>
I talked with Patrick about this. Since we don't have a fallback
implementation for the following traits, it would be better to keep
the current implementation instead of using
_GLIBCXX_USE_BUILTIN_TRAIT. For _GLIBCXX_HAS_BUILTIN, if it works
with Clang 14, I will submit a patch. Thank you!
> > * _GLIBCXX_HAVE_BUILTIN_HAS_UNIQ_OBJ_REP
> > * _GLIBCXX_HAVE_BUILTIN_IS_AGGREGATE
> > * _GLIBCXX_HAVE_BUILTIN_LAUNDER
> > At some point we should also simplify this:
> >
> > #ifdef __has_builtin
> > # ifdef __is_identifier
> > // Intel and older Clang require !__is_identifier for some built-ins:
> > # define _GLIBCXX_HAS_BUILTIN(B) __has_builtin(B) || ! __is_identifier(B)
> > # else
> > # define _GLIBCXX_HAS_BUILTIN(B) __has_builtin(B)
> > # endif
> > #endif
> >
> > I think we can stop supporting old versions of Clang where __is_builtin
> > (__is_same) is false, but we should verify which version of Clang stopped
> > requiring !__is_identifier for those built-ins. If it's older than Clang 14 we
> > can remove _GLIBCXX_HAS_BUILTIN and just use __has_builtin directly in
> > _GLIBCXX_USE_BUILTIN_TRAIT. That should wait for GCC 15 though.
> >
> >
> >
> >
> >
>
> --
> Ken Matsui
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2024-02-13 23:35 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-07 21:58 Question about _GLIBCXX_HAVE_BUILTIN_IS_SAME Ken Matsui
2024-02-08 0:13 ` Jonathan Wakely
2024-02-09 19:35 ` Ken Matsui
2024-02-13 23:34 ` Ken Matsui
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).