• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1From 32d07c1ed42529efeb0664d4232bc5c94eedb6a9 Mon Sep 17 00:00:00 2001
2From: Andrew Hsieh <andrewhsieh@google.com>
3Date: Sun, 27 Apr 2014 22:19:17 -0700
4Subject: [PATCH 06/12] Emulate __has_feature() for GCC
5
6__config defines dozens of _LIBCPP_* flags based on the compiler support of
7language features: for clang it uses __has_feature() to discover; for gcc most
8flags are hard-coded based on gcc version.  Unfortunately some code in libc++
9still use __has_features() directly instead of _LIBCPP_* flags. This CL emulates
10__has_feature() for GCC (from the default "0")
11---
12 include/__config | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
13 1 file changed, 60 insertions(+)
14
15diff --git a/include/__config b/include/__config
16index 64519b7..df84ac6 100644
17--- a/include/__config
18+++ b/include/__config
19@@ -434,6 +434,66 @@ using namespace _LIBCPP_NAMESPACE __attribute__((__strong__));
20 #define _LIBCPP_HAS_NO_ASAN
21 #endif
22
23+// Emulation of clang's __has_feature() for GCC on known cases
24+#ifndef __has_feature
25+
26+#define __gxx__cxx_access_control_sfinae          !defined(_LIBCPP_HAS_NO_TRAILING_RETURN) || !defined(_LIBCPP_HAS_NO_ADVANCED_SFINAE) // Also see usage in 7 tests
27+#define __gxx__cxx_alias_templates                !defined(_LIBCPP_HAS_NO_TEMPLATE_ALIASES)
28+#define __gxx__cxx_address_sanitizer              !defined(_LIBCPP_HAS_NO_ASAN)
29+#define __gxx__cxx_alignas                        0  // Not sure, doesn't matter.
30+#define __gxx__cxx_atomic                         0  // (_GNUC_VER >= 409) seems to support _Atomic in -std=c11 not -std=c++11 !
31+#define __gxx__cxx_attributes                     0  // Not sure. Also see usage in libcxx/test/utilities/meta/meta.unary/meta.unary.prop/is_polymorphic.pass.cpp
32+#define __gxx__cxx_auto_type                      !defined(_LIBCPP_HAS_NO_AUTO_TYPE)
33+#define __gxx__cxx_constexpr                      !defined(_LIBCPP_HAS_NO_CONSTEXPR)
34+#define __gxx__cxx_decltype                       !defined(_LIBCPP_HAS_NO_DECLTYPE)
35+#define __gxx__cxx_defaulted_functions            !defined(_LIBCPP_HAS_NO_DEFAULTED_FUNCTIONS)  // libcxx/test/utilities/meta/meta.unary/meta.unary.prop/is_trivially_move_constructible.pass.cpp
36+#define __gxx__cxx_deleted_functions              !defined(_LIBCPP_HAS_NO_DELETED_FUNCTIONS)
37+#define __gxx__cxx_exceptions                     !defined(_LIBCPP_NO_EXCEPTIONS)
38+#define __gxx__cxx_explicit_conversions           (_GNUC_VER >= 405)
39+#define __gxx__cxx_generalized_initializers       !defined(_LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS)
40+#define __gxx__cxx_lambdas                        !defined(_LIBCPP_HAS_NO_LAMBDAS)
41+#define __gxx__cxx_noexcept                       0  // Not sure, doesn't matter.
42+#define __gxx__cxx_nullptr                        !defined(_LIBCPP_HAS_NO_NULLPTR)
43+#define __gxx__cxx_reference_qualified_functions  (_GNUC_VER >= 408)  // Not if 4.7 work. 4.6 certainly not.  Also see usage in libcxx/include/type_traits
44+#ifdef _LIBCPP_NO_RTTI
45+#define __gxx__cxx_rtti                           0
46+#else
47+#define __gxx__cxx_rtti                           __GXX_RTTI
48+#endif
49+#define __gxx__cxx_rvalue_references              !defined(_LIBCPP_HAS_NO_RVALUE_REFERENCES)
50+#define __gxx__cxx_static_assert                  !defined(_LIBCPP_HAS_NO_STATIC_ASSERT)
51+#define __gxx__cxx_strong_enums                   !defined(_LIBCPP_HAS_NO_STRONG_ENUMS)  // See usage in libcxx/test/utilities/meta/meta.trans/meta.trans.other/underlying_type.pass.cpp
52+#define __gxx__cxx_trailing_return                !defined(_LIBCPP_HAS_NO_TRAILING_RETURN)
53+#define __gxx__cxx_unrestricted_unions            1  // Not sure.  Also See usage in libcxx/test/utilities/meta/meta.unary/meta.unary.prop/is_nothrow_destructible.pass.cpp
54+#define __gxx__cxx_variadic_templates             !defined(_LIBCPP_HAS_NO_VARIADICS)
55+#define __gxx__has_nothrow_assign                 (_GNUC_VER >= 403)  // See usage in libcxx/include/type_traits
56+#define __gxx__has_nothrow_constructor            (_GNUC_VER >= 403)  // See usage in libcxx/include/type_traits
57+#define __gxx__has_nothrow_copy                   (_GNUC_VER >= 403)  // See usage in libcxx/include/type_traits
58+#define __gxx__has_trivial_constructor            (_GNUC_VER >= 403)  // See usage in libcxx/include/type_traits
59+#define __gxx__has_trivial_destructor             (_GNUC_VER >= 403)  // See usage in libcxx/include/type_traits
60+#define __gxx__has_virtual_destructor             (_GNUC_VER >= 403)  // See usage in libcxx/include/type_traits
61+#define __gxx__is_base_of                         !defined(_LIBCPP_HAS_IS_BASE_OF)  // See usage in libcxx/include/type_traits
62+#define __gxx__is_class                           (_GNUC_VER >= 403)  // See usage in libcxx/include/type_traits
63+#define __gxx__is_convertible_to                  0  // Not supported in GCC 4.8.  Also see usage in libcxx/include/type_traits
64+#define __gxx__is_empty                           1  // Not sure.  Also see usage in libcxx/include/type_traits
65+#define __gxx__is_enum                            (_GNUC_VER >= 403)  // See usage in libcxx/include/type_traits
66+#define __gxx__is_final                           (_GNUC_VER >= 408)  // Not if 4.7 work. 4.6 certainly not.  Also see usage in libcxx/include/unordered_map,tuple,ext/hash_map,map,memory
67+#define __gxx__is_literal                         0  // Not supported in GCC 4.8.  Also see usage in libcxx/include/type_traits
68+#define __gxx__is_pod                             (_GNUC_VER >= 403)  // See usage in libcxx/include/type_traits
69+#define __gxx__is_polymorphic                     1  // Not sure.  Also see usage in libcxx/include/type_traits
70+#define __gxx__is_standard_layout                 1  // Not sure.  Also see usage in libcxx/include/type_traits
71+#define __gxx__is_trivial                         0  // Not supported in GCC 4.8.  Also see usage in libcxx/include/type_traits
72+#define __gxx__is_trivially_constructible         0  // Not supported in GCC 4.8.  Also see usage in libcxx/include/type_traits
73+#define __gxx__is_trivially_copyable              0  // Not supported in GCC 4.8.  Also see usage in libcxx/include/type_traits
74+#define __gxx__is_union                           (_GNUC_VER >= 403)  // See usage in libcxx/include/type_traits
75+#define __gxx__objc_arc                           defined(_LIBCPP_HAS_OBJC_ARC)
76+#define __gxx__objc_arc_weak                      defined(_LIBCPP_HAS_OBJC_ARC_WEAK)
77+#define __gxx__underlying_type                    1  // Not sure.  Also see usage in libcxx/include/type_traits
78+
79+#define __has_feature(__x) __gxx__ ## __x
80+
81+#endif // __has_feature
82+
83 #elif defined(_LIBCPP_MSVC)
84
85 #define _LIBCPP_HAS_NO_TEMPLATE_ALIASES
86--
871.9.1.423.g4596e3a
88
89