浏览代码

has_trivial_default_constructor hooked up to clang. Filed http://llvm.org/bugs/show_bug.cgi?id=8097 to take care of void and arrays of incomplete types which don't work yet. If there is some reasons we don't want to handle these types in the compiler, I can handle them in the library.

git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@113205 91177308-0d34-0410-b5e6-96231b3b80d8
Howard Hinnant 15 年之前
父节点
当前提交
2fd6d25bf1

+ 16 - 7
include/type_traits

@@ -114,7 +114,6 @@ namespace std
     template <class T, class U> struct is_same;
     template <class Base, class Derived> struct is_base_of;
     template <class From, class To> struct is_convertible;
-    template <class T> struct underlying_type;
 
     // Alignment properties and transformations:
     template <class T> struct alignment_of;
@@ -698,11 +697,21 @@ template <class _Tp> struct is_polymorphic : public __libcpp_polymorphic<_Tp> {}
 
 // has_trivial_default_constructor
 
-template <class _Tp> struct __has_trivial_default_constructor : public integral_constant<bool, is_scalar<_Tp>::value> {};
+#if __GNUC__ >= 4 && __GNUC_MINOR__ >= 3 || defined(__clang__)
+
+template <class _Tp> struct has_trivial_default_constructor
+    : public integral_constant<bool, __has_trivial_constructor(_Tp)> {};
+
+#else  // __GNUC__ >= 4 && __GNUC_MINOR__ >= 3 || defined(__clang__)
+
+template <class _Tp> struct __has_trivial_default_constructor
+    : public integral_constant<bool, is_scalar<_Tp>::value> {};
 
 template <class _Tp> struct has_trivial_default_constructor
     : public __has_trivial_default_constructor<typename remove_all_extents<_Tp>::type> {};
 
+#endif  // __GNUC__ >= 4 && __GNUC_MINOR__ >= 3 || defined(__clang__)
+
 // has_nothrow_default_constructor
 
 template <class _Tp> struct has_nothrow_default_constructor : public has_trivial_default_constructor<_Tp> {};
@@ -1493,6 +1502,11 @@ class result_of<_Fn(_A0, _A1, _A2)>
 
 #endif  // _LIBCPP_HAS_NO_VARIADICS
 
+struct __any
+{
+    __any(...);
+};
+
 #ifndef _LIBCPP_HAS_NO_ADVANCED_SFINAE
 
 // template <class T, class... Args> struct is_constructible;
@@ -1503,11 +1517,6 @@ template <class _Tp, class ..._Args>
 decltype(_STD::move(_Tp(_STD::declval<_Args>()...)), true_type())
 __is_constructible_test(_Tp&&, _Args&& ...);
 
-struct __any
-{
-    __any(...);
-};
-
 template <class ..._Args>
 false_type
 __is_constructible_test(__any, _Args&& ...);

+ 3 - 3
test/utilities/meta/meta.unary/meta.unary.prop/has_trivial_default_constructor.pass.cpp

@@ -62,16 +62,16 @@ int main()
     test_has_not_trivial_default_constructor<void>();
     test_has_not_trivial_default_constructor<int&>();
     test_has_not_trivial_default_constructor<A>();
+    test_has_not_trivial_default_constructor<Abstract>();
+    test_has_not_trivial_default_constructor<NotEmpty>();
+    test_has_not_trivial_default_constructor<char[]>();
 
     test_has_trivial_default_constructor<Union>();
-    test_has_trivial_default_constructor<Abstract>();
     test_has_trivial_default_constructor<Empty>();
     test_has_trivial_default_constructor<int>();
     test_has_trivial_default_constructor<double>();
     test_has_trivial_default_constructor<int*>();
     test_has_trivial_default_constructor<const int*>();
     test_has_trivial_default_constructor<char[3]>();
-    test_has_trivial_default_constructor<char[3]>();
-    test_has_trivial_default_constructor<NotEmpty>();
     test_has_trivial_default_constructor<bit_zero>();
 }