libstdc++: Define _GLIBCXX_HAS_BUILTIN_TRAIT

Message ID 20230718223233.15328-1-kmatsui@gcc.gnu.org
State Accepted
Headers
Series libstdc++: Define _GLIBCXX_HAS_BUILTIN_TRAIT |

Checks

Context Check Description
snail/gcc-patch-check success Github commit url

Commit Message

Ken Matsui July 18, 2023, 10:32 p.m. UTC
  This patch defines _GLIBCXX_HAS_BUILTIN_TRAIT, which will be used as a
flag to toggle built-in traits in the type_traits header. Through this
macro function and _GLIBCXX_NO_BUILTIN_TRAITS macro, we can switch the
use of built-in traits without needing to modify the source code.

libstdc++-v3/ChangeLog:

	* include/bits/c++config (_GLIBCXX_HAS_BUILTIN_TRAIT): Define.

Signed-off-by: Ken Matsui <kmatsui@gcc.gnu.org>
---
 libstdc++-v3/include/bits/c++config | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
  

Comments

Patrick Palka July 19, 2023, 6:48 p.m. UTC | #1
On Tue, 18 Jul 2023, Ken Matsui via Libstdc++ wrote:

> This patch defines _GLIBCXX_HAS_BUILTIN_TRAIT, which will be used as a
> flag to toggle built-in traits in the type_traits header. Through this
> macro function and _GLIBCXX_NO_BUILTIN_TRAITS macro, we can switch the
> use of built-in traits without needing to modify the source code.
> 
> libstdc++-v3/ChangeLog:
> 
> 	* include/bits/c++config (_GLIBCXX_HAS_BUILTIN_TRAIT): Define.

The ChangeLog entry should also mention the change to _GLIBCXX_HAS_BUILTIN,
e.g.

	(_GLIBCXX_HAS_BUILTIN): Keep defined.

> 
> Signed-off-by: Ken Matsui <kmatsui@gcc.gnu.org>
> ---
>  libstdc++-v3/include/bits/c++config | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/libstdc++-v3/include/bits/c++config b/libstdc++-v3/include/bits/c++config
> index dd47f274d5f..de13f61db71 100644
> --- a/libstdc++-v3/include/bits/c++config
> +++ b/libstdc++-v3/include/bits/c++config
> @@ -854,7 +854,11 @@ namespace __gnu_cxx
>  # define _GLIBCXX_HAVE_BUILTIN_LAUNDER 1
>  #endif
>  
> -#undef _GLIBCXX_HAS_BUILTIN
> +// Returns true if _GLIBCXX_NO_BUILTIN_TRAITS is not defined and the compiler
> +// has a corresponding built-in type trait. _GLIBCXX_NO_BUILTIN_TRAITS is
> +// defined to disable the use of built-in traits.
> +#define _GLIBCXX_HAS_BUILTIN_TRAIT(BT)  \
> +  (!defined(_GLIBCXX_NO_BUILTIN_TRAITS) && _GLIBCXX_HAS_BUILTIN(BT))

Since we don't expect _GLIBCXX_NO_BUILTIN_TRAITS to get
defined/undefined in the middle of preprocessing, perhaps we should
factor out the _GLIBCXX_NO_BUILTIN_TRAITS test from the macro function
and instead conditionally define the macro function to 0 according
_GLIBCXX_NO_BUILTIN_TRAITS?

>  
>  // Mark code that should be ignored by the compiler, but seen by Doxygen.
>  #define _GLIBCXX_DOXYGEN_ONLY(X)
> -- 
> 2.41.0
> 
>
  
Ken Matsui July 19, 2023, 7:31 p.m. UTC | #2
On Wed, Jul 19, 2023 at 11:48 AM Patrick Palka <ppalka@redhat.com> wrote:
>
> On Tue, 18 Jul 2023, Ken Matsui via Libstdc++ wrote:
>
> > This patch defines _GLIBCXX_HAS_BUILTIN_TRAIT, which will be used as a
> > flag to toggle built-in traits in the type_traits header. Through this
> > macro function and _GLIBCXX_NO_BUILTIN_TRAITS macro, we can switch the
> > use of built-in traits without needing to modify the source code.
> >
> > libstdc++-v3/ChangeLog:
> >
> >       * include/bits/c++config (_GLIBCXX_HAS_BUILTIN_TRAIT): Define.
>
> The ChangeLog entry should also mention the change to _GLIBCXX_HAS_BUILTIN,
> e.g.
>
>         (_GLIBCXX_HAS_BUILTIN): Keep defined.
>
> >
> > Signed-off-by: Ken Matsui <kmatsui@gcc.gnu.org>
> > ---
> >  libstdc++-v3/include/bits/c++config | 6 +++++-
> >  1 file changed, 5 insertions(+), 1 deletion(-)
> >
> > diff --git a/libstdc++-v3/include/bits/c++config b/libstdc++-v3/include/bits/c++config
> > index dd47f274d5f..de13f61db71 100644
> > --- a/libstdc++-v3/include/bits/c++config
> > +++ b/libstdc++-v3/include/bits/c++config
> > @@ -854,7 +854,11 @@ namespace __gnu_cxx
> >  # define _GLIBCXX_HAVE_BUILTIN_LAUNDER 1
> >  #endif
> >
> > -#undef _GLIBCXX_HAS_BUILTIN
> > +// Returns true if _GLIBCXX_NO_BUILTIN_TRAITS is not defined and the compiler
> > +// has a corresponding built-in type trait. _GLIBCXX_NO_BUILTIN_TRAITS is
> > +// defined to disable the use of built-in traits.
> > +#define _GLIBCXX_HAS_BUILTIN_TRAIT(BT)  \
> > +  (!defined(_GLIBCXX_NO_BUILTIN_TRAITS) && _GLIBCXX_HAS_BUILTIN(BT))
>
> Since we don't expect _GLIBCXX_NO_BUILTIN_TRAITS to get
> defined/undefined in the middle of preprocessing, perhaps we should
> factor out the _GLIBCXX_NO_BUILTIN_TRAITS test from the macro function
> and instead conditionally define the macro function to 0 according
> _GLIBCXX_NO_BUILTIN_TRAITS?
>
Hi, thank you for your review! I totally agree with your ideas and
will update this patch.

> >
> >  // Mark code that should be ignored by the compiler, but seen by Doxygen.
> >  #define _GLIBCXX_DOXYGEN_ONLY(X)
> > --
> > 2.41.0
> >
> >
>
  
Jonathan Wakely Aug. 8, 2023, 8:22 p.m. UTC | #3
On Wed, 19 Jul 2023 at 19:48, Patrick Palka via Libstdc++ <
libstdc++@gcc.gnu.org> wrote:

> On Tue, 18 Jul 2023, Ken Matsui via Libstdc++ wrote:
>
> > This patch defines _GLIBCXX_HAS_BUILTIN_TRAIT, which will be used as a
> > flag to toggle built-in traits in the type_traits header. Through this
> > macro function and _GLIBCXX_NO_BUILTIN_TRAITS macro, we can switch the
> > use of built-in traits without needing to modify the source code.
> >
> > libstdc++-v3/ChangeLog:
> >
> >       * include/bits/c++config (_GLIBCXX_HAS_BUILTIN_TRAIT): Define.
>
> The ChangeLog entry should also mention the change to _GLIBCXX_HAS_BUILTIN,
> e.g.
>
>         (_GLIBCXX_HAS_BUILTIN): Keep defined.
>
> >
> > Signed-off-by: Ken Matsui <kmatsui@gcc.gnu.org>
> > ---
> >  libstdc++-v3/include/bits/c++config | 6 +++++-
> >  1 file changed, 5 insertions(+), 1 deletion(-)
> >
> > diff --git a/libstdc++-v3/include/bits/c++config
> b/libstdc++-v3/include/bits/c++config
> > index dd47f274d5f..de13f61db71 100644
> > --- a/libstdc++-v3/include/bits/c++config
> > +++ b/libstdc++-v3/include/bits/c++config
> > @@ -854,7 +854,11 @@ namespace __gnu_cxx
> >  # define _GLIBCXX_HAVE_BUILTIN_LAUNDER 1
> >  #endif
> >
> > -#undef _GLIBCXX_HAS_BUILTIN
> > +// Returns true if _GLIBCXX_NO_BUILTIN_TRAITS is not defined and the
> compiler
> > +// has a corresponding built-in type trait. _GLIBCXX_NO_BUILTIN_TRAITS
> is
> > +// defined to disable the use of built-in traits.
> > +#define _GLIBCXX_HAS_BUILTIN_TRAIT(BT)  \
> > +  (!defined(_GLIBCXX_NO_BUILTIN_TRAITS) && _GLIBCXX_HAS_BUILTIN(BT))
>
> Since we don't expect _GLIBCXX_NO_BUILTIN_TRAITS to get
> defined/undefined in the middle of preprocessing, perhaps we should
> factor out the _GLIBCXX_NO_BUILTIN_TRAITS test from the macro function
> and instead conditionally define the macro function to 0 according
> _GLIBCXX_NO_BUILTIN_TRAITS?
>

Also a macro that expands to a use of `defined`  is undefined, see
[cpp.cond] p10.

GCC allows it, but Clang warns.




> >
> >  // Mark code that should be ignored by the compiler, but seen by
> Doxygen.
> >  #define _GLIBCXX_DOXYGEN_ONLY(X)
> > --
> > 2.41.0
> >
> >
>
>
  

Patch

diff --git a/libstdc++-v3/include/bits/c++config b/libstdc++-v3/include/bits/c++config
index dd47f274d5f..de13f61db71 100644
--- a/libstdc++-v3/include/bits/c++config
+++ b/libstdc++-v3/include/bits/c++config
@@ -854,7 +854,11 @@  namespace __gnu_cxx
 # define _GLIBCXX_HAVE_BUILTIN_LAUNDER 1
 #endif
 
-#undef _GLIBCXX_HAS_BUILTIN
+// Returns true if _GLIBCXX_NO_BUILTIN_TRAITS is not defined and the compiler
+// has a corresponding built-in type trait. _GLIBCXX_NO_BUILTIN_TRAITS is
+// defined to disable the use of built-in traits.
+#define _GLIBCXX_HAS_BUILTIN_TRAIT(BT)  \
+  (!defined(_GLIBCXX_NO_BUILTIN_TRAITS) && _GLIBCXX_HAS_BUILTIN(BT))
 
 // Mark code that should be ignored by the compiler, but seen by Doxygen.
 #define _GLIBCXX_DOXYGEN_ONLY(X)