[PATCH] PR libstdc++/80446 cope with libc defining __has_builtin

Jonathan Wakely jwakely@redhat.com
Wed Apr 19 10:49:00 GMT 2017


Both newlib and FreeBSD have this in libc headers:

#ifndef __has_builtin
#define __has_builtin(x) 0
#endif

This means our attempts to use #ifdef __has_builtin aren't reliable,
so we need a different approach. With this patch we don't care whether
it's defined or not, only its value.

	PR libstdc++/80446
	* include/std/type_traits (is_aggregate): Change __has_builtin checks.
	* libsupc++/new (launder): Likewise.

Tested ppc64le-linux and x86_64-freebsd11.0, committed to trunk.


-------------- next part --------------
commit 5c3b069722fb9182972fa551a83cc10f42c6fbce
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Wed Apr 19 10:57:59 2017 +0100

    PR libstdc++/80446 cope with libc defining __has_builtin
    
    	PR libstdc++/80446
    	* include/std/type_traits (is_aggregate): Change __has_builtin checks.
    	* libsupc++/new (launder): Likewise.

diff --git a/libstdc++-v3/include/std/type_traits b/libstdc++-v3/include/std/type_traits
index 8ea2801..aac7cff 100644
--- a/libstdc++-v3/include/std/type_traits
+++ b/libstdc++-v3/include/std/type_traits
@@ -3062,14 +3062,16 @@ template <typename _From, typename _To>
 #endif
 #undef _GLIBCXX_NO_BUILTIN_HAS_UNIQ_OBJ_REP
 
-#ifdef __has_builtin
-# if !__has_builtin(__is_aggregate)
-// Try not to break non-GNU compilers that don't support the built-in:
-#  define _GLIBCXX_NO_BUILTIN_IS_AGGREGATE 1
+#if __GNUC__ >= 7
+# define _GLIBCXX_HAVE_BUILTIN_IS_AGGREGATE 1
+#elif defined __has_builtin
+// For non-GNU compilers:
+# if __has_builtin(__is_aggregate)
+#  define _GLIBCXX_HAVE_BUILTIN_IS_AGGREGATE 1
 # endif
 #endif
 
-#ifndef _GLIBCXX_NO_BUILTIN_IS_AGGREGATE
+#ifdef _GLIBCXX_HAVE_BUILTIN_IS_AGGREGATE
 #define __cpp_lib_is_aggregate 201703
   /// is_aggregate
   template<typename _Tp>
@@ -3080,7 +3082,7 @@ template <typename _From, typename _To>
   template<typename _Tp>
     inline constexpr bool is_aggregate_v = is_aggregate<_Tp>::value;
 #endif
-#undef _GLIBCXX_NO_BUILTIN_IS_AGGREGATE
+#undef _GLIBCXX_HAVE_BUILTIN_IS_AGGREGATE
 
 #endif // C++17
 
diff --git a/libstdc++-v3/libsupc++/new b/libstdc++-v3/libsupc++/new
index 9a7859d..2de7752 100644
--- a/libstdc++-v3/libsupc++/new
+++ b/libstdc++-v3/libsupc++/new
@@ -177,14 +177,16 @@ inline void operator delete[](void*, void*) _GLIBCXX_USE_NOEXCEPT { }
 } // extern "C++"
 
 #if __cplusplus > 201402L
-#ifdef __has_builtin
-# if !__has_builtin(__builtin_launder)
-// Try not to break non-GNU compilers that don't support the built-in:
-#  define _GLIBCXX_NO_BUILTIN_LAUNDER 1
+#if __GNUC__ >= 7
+#  define _GLIBCXX_HAVE_BUILTIN_LAUNDER 1
+#elif defined __has_builtin
+// For non-GNU compilers:
+# if __has_builtin(__builtin_launder)
+#  define _GLIBCXX_HAVE_BUILTIN_LAUNDER 1
 # endif
 #endif
 
-#ifndef _GLIBCXX_NO_BUILTIN_LAUNDER
+#ifdef _GLIBCXX_HAVE_BUILTIN_LAUNDER
 namespace std
 {
 #define __cpp_lib_launder 201606
@@ -208,7 +210,7 @@ namespace std
   void launder(const volatile void*) = delete;
 }
 #endif // _GLIBCXX_NO_BUILTIN_LAUNDER
-#undef _GLIBCXX_NO_BUILTIN_LAUNDER
+#undef _GLIBCXX_HAVE_BUILTIN_LAUNDER
 #endif // C++17
 
 #pragma GCC visibility pop


More information about the Libstdc++ mailing list