]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
PR c++/90532 Ensure __is_constructible(T[]) is false
authorJonathan Wakely <jwakely@redhat.com>
Mon, 20 May 2019 11:32:51 +0000 (12:32 +0100)
committerJonathan Wakely <redi@gcc.gnu.org>
Mon, 20 May 2019 11:32:51 +0000 (12:32 +0100)
An array of an unknown bound is an incomplete type, so no object of such
a type can be constructed. This means __is_constructible should always
be false for an array of unknown bound.

This patch also changes the std::is_default_constructible trait to use
std::is_constructible, which now gives the right answer for arrays of
unknown bound.

gcc/cp:

PR c++/90532 Ensure __is_constructible(T[]) is false
* method.c (is_xible_helper): Return error_mark_node for construction
of an array of unknown bound.

gcc/testsuite:

PR c++/90532 Ensure __is_constructible(T[]) is false
* g++.dg/ext/90532.C: New test.

libstdc++-v3:

PR c++/90532 Ensure __is_constructible(T[]) is false
* include/std/type_traits (__do_is_default_constructible_impl)
(__is_default_constructible_atom, __is_default_constructible_safe):
Remove.
(is_default_constructible): Use is_constructible.
* testsuite/20_util/is_constructible/value.cc: Check int[] case.
* testsuite/20_util/is_default_constructible/value.cc: Likewise.
* testsuite/20_util/is_trivially_constructible/value.cc: Likewise.
* testsuite/20_util/is_trivially_default_constructible/value.cc:
Likewise.

From-SVN: r271412

gcc/cp/ChangeLog
gcc/cp/method.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/ext/90532.C [new file with mode: 0644]
libstdc++-v3/ChangeLog
libstdc++-v3/include/std/type_traits
libstdc++-v3/testsuite/20_util/is_constructible/value.cc
libstdc++-v3/testsuite/20_util/is_default_constructible/value.cc
libstdc++-v3/testsuite/20_util/is_trivially_constructible/value.cc
libstdc++-v3/testsuite/20_util/is_trivially_default_constructible/value.cc

index 39aaab966c90839d1398e712e0166208ec24a849..c8eb936aec378ea97026ae69f630b63bf6e1a5fa 100644 (file)
@@ -1,3 +1,9 @@
+2019-05-20  Jonathan Wakely  <jwakely@redhat.com>
+
+       PR c++/90532 Ensure __is_constructible(T[]) is false
+       * method.c (is_xible_helper): Return error_mark_node for construction
+       of an array of unknown bound.
+
 2019-05-17  Thomas Schwinge  <thomas@codesourcery.com>
 
        PR c++/89433
index 3fb3b5a9091286d9572377367d85f86da2ffa4ed..53fa85b9790f87e1b7f115c2353e012989d30e40 100644 (file)
@@ -1201,6 +1201,8 @@ is_xible_helper (enum tree_code code, tree to, tree from, bool trivial)
     expr = assignable_expr (to, from);
   else if (trivial && from && TREE_CHAIN (from))
     return error_mark_node; // only 0- and 1-argument ctors can be trivial
+  else if (TREE_CODE (to) == ARRAY_TYPE && !TYPE_DOMAIN (to))
+    return error_mark_node; // can't construct an array of unknown bound
   else
     expr = constructible_expr (to, from);
   return expr;
index 3ecff36b7b5e76f57eeccc71750af00d118034b3..36db11bb183c201dcea4a705aa7c3ca47dcc2566 100644 (file)
@@ -1,3 +1,8 @@
+2019-05-20  Jonathan Wakely  <jwakely@redhat.com>
+
+       PR c++/90532 Ensure __is_constructible(T[]) is false
+       * g++.dg/ext/90532.C: New test.
+
 2019-05-20  Jakub Jelinek  <jakub@redhat.com>
 
        * gcc.target/i386/avx512f-simd-1.c: New test.
diff --git a/gcc/testsuite/g++.dg/ext/90532.C b/gcc/testsuite/g++.dg/ext/90532.C
new file mode 100644 (file)
index 0000000..acdc4e2
--- /dev/null
@@ -0,0 +1,27 @@
+// { dg-do compile { target c++11 } }
+// PR c++/90532
+static_assert( !__is_constructible(int[]), "" );
+static_assert( !__is_constructible(int[], int), "" );
+static_assert( !__is_constructible(int[], int[]), "" );
+static_assert( !__is_trivially_constructible(int[]), "" );
+static_assert( !__is_trivially_constructible(int[], int), "" );
+static_assert( !__is_trivially_constructible(int[], int[]), "" );
+static_assert( !__is_trivially_constructible(int[], int(&)[]), "" );
+static_assert( !__is_trivially_constructible(int[], void), "" );
+struct A { };
+static_assert( !__is_constructible(A[]), "" );
+static_assert( !__is_constructible(A[], const A&), "" );
+static_assert( !__is_constructible(A[], const A[]), "" );
+static_assert( !__is_trivially_constructible(A[]), "" );
+static_assert( !__is_trivially_constructible(A[], const A&), "" );
+static_assert( !__is_trivially_constructible(A[], const A[]), "" );
+static_assert( !__is_trivially_constructible(A[], A(&)[]), "" );
+static_assert( !__is_trivially_constructible(A[], void), "" );
+struct B { B(); };
+static_assert( !__is_constructible(B[]), "" );
+static_assert( !__is_constructible(B[], const B&), "" );
+static_assert( !__is_trivially_constructible(B[]), "" );
+static_assert( !__is_trivially_constructible(B[], const B&), "" );
+static_assert( !__is_trivially_constructible(B[], const B[]), "" );
+static_assert( !__is_trivially_constructible(B[], B(&)[]), "" );
+static_assert( !__is_trivially_constructible(B[], void), "" );
index 74717dea5a03d5c4c36fb6ad4d50398ac9563f83..c5b8d6016b0d7f403877905e6ec9987fd5c66433 100644 (file)
@@ -1,3 +1,16 @@
+2019-05-20  Jonathan Wakely  <jwakely@redhat.com>
+
+       PR c++/90532 Ensure __is_constructible(T[]) is false
+       * include/std/type_traits (__do_is_default_constructible_impl)
+       (__is_default_constructible_atom, __is_default_constructible_safe):
+       Remove.
+       (is_default_constructible): Use is_constructible.
+       * testsuite/20_util/is_constructible/value.cc: Check int[] case.
+       * testsuite/20_util/is_default_constructible/value.cc: Likewise.
+       * testsuite/20_util/is_trivially_constructible/value.cc: Likewise.
+       * testsuite/20_util/is_trivially_default_constructible/value.cc:
+       Likewise.
+
 2019-05-20  Pádraig Brady  <pbrady@fb.com>
 
        * libstdc++-v3/include/ext/new_allocator.h (deallocate): Pass the size
index b1c3e943e791cc914b5c598b0590102c0e67424e..3a622eb61e01a493347ea7bb4447dd0861b37fc2 100644 (file)
@@ -878,58 +878,16 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     : public __is_nt_destructible_safe<_Tp>::type
     { };
 
-  struct __do_is_default_constructible_impl
-  {
-    template<typename _Tp, typename = decltype(_Tp())>
-      static true_type __test(int);
-
-    template<typename>
-      static false_type __test(...);
-  };
-
-  template<typename _Tp>
-    struct __is_default_constructible_impl
-    : public __do_is_default_constructible_impl
-    {
-      typedef decltype(__test<_Tp>(0)) type;
-    };
-
-  template<typename _Tp>
-    struct __is_default_constructible_atom
-    : public __and_<__not_<is_void<_Tp>>,
-                    __is_default_constructible_impl<_Tp>>
-    { };
-
-  template<typename _Tp, bool = is_array<_Tp>::value>
-    struct __is_default_constructible_safe;
-
-  // The following technique is a workaround for a current core language
-  // restriction, which does not allow for array types to occur in
-  // functional casts of the form T().  Complete arrays can be default-
-  // constructed, if the element type is default-constructible, but
-  // arrays with unknown bounds are not.
-  template<typename _Tp>
-    struct __is_default_constructible_safe<_Tp, true>
-    : public __and_<__is_array_known_bounds<_Tp>,
-                   __is_default_constructible_atom<typename
-                      remove_all_extents<_Tp>::type>>
-    { };
-
-  template<typename _Tp>
-    struct __is_default_constructible_safe<_Tp, false>
-    : public __is_default_constructible_atom<_Tp>::type
+  /// is_constructible
+  template<typename _Tp, typename... _Args>
+    struct is_constructible
+      : public __bool_constant<__is_constructible(_Tp, _Args...)>
     { };
 
   /// is_default_constructible
   template<typename _Tp>
     struct is_default_constructible
-    : public __is_default_constructible_safe<_Tp>::type
-    { };
-
-  /// is_constructible
-  template<typename _Tp, typename... _Args>
-    struct is_constructible
-      : public __bool_constant<__is_constructible(_Tp, _Args...)>
+    : public is_constructible<_Tp>::type
     { };
 
   template<typename _Tp, bool = __is_referenceable<_Tp>::value>
index acd7a5f5703a0b6f01d55748b214a558a87a3d7f..a8b40921d929ee67b26c9969e21002fcdf641efb 100644 (file)
@@ -35,4 +35,11 @@ void test01()
   static_assert(test_property<is_constructible, ExplicitClass>(false), "");
   static_assert(test_property<is_constructible, ExplicitClass,
                int, double>(false), "");
+  static_assert(test_property<is_constructible, int[]>(false), "PR c++/90532");
+  static_assert(test_property<is_constructible,
+               __gnu_test::construct::Empty[]>(false), "PR c++/90532");
+  static_assert(test_property<is_constructible,
+               __gnu_test::construct::Ukn[]>(false), "PR c++/90532");
+  static_assert(test_property<is_constructible,
+               __gnu_test::construct::nAny[]>(false), "PR c++/90532");
 }
index bd66ed0ab92354c8d8a50c50d164fc5235f7804f..f6df45d841bc9f696e2c7ded411d3638a745a5ca 100644 (file)
@@ -138,3 +138,13 @@ static_assert(!std::is_default_constructible<DelCopy>::value, "Error");
 static_assert(!std::is_default_constructible<const DelCopy>::value, "Error");
 static_assert(!std::is_default_constructible<DelDtor>::value, "Error");
 static_assert(!std::is_default_constructible<const DelDtor>::value, "Error");
+
+static_assert(!std::is_default_constructible<int[]>::value, "PR c++/90532");
+static_assert(!std::is_default_constructible<Empty[]>::value, "PR c++/90532");
+static_assert(!std::is_default_constructible<B[]>::value, "PR c++/90532");
+static_assert(!std::is_default_constructible<D[]>::value, "PR c++/90532");
+static_assert(!std::is_default_constructible<U[]>::value, "PR c++/90532");
+static_assert(!std::is_default_constructible<Ukn[]>::value, "PR c++/90532");
+static_assert(!std::is_default_constructible<Ellipsis[]>::value, "PR c++/90532");
+static_assert(!std::is_default_constructible<Any[]>::value, "PR c++/90532");
+static_assert(!std::is_default_constructible<nAny[]>::value, "PR c++/90532");
index 0c8ad62dbbce251551435d561ee1e8e15627e7d9..0979ceff7e37f686f8d6a5129ed8db9857c9f8ce 100644 (file)
@@ -180,4 +180,6 @@ void test01()
                MoveOnly, const MoveOnly&>(false), "");
   static_assert(test_property<is_trivially_constructible,
                MoveOnly2>(false), "");
+  static_assert(test_property<is_trivially_constructible,
+               int[]>(false), "PR c++/90532");
 }
index 8baca915df31119386c3a3b250b413ea111d4528..f457721925d2e5758aa57a878d72d740ebda0c33 100644 (file)
@@ -62,4 +62,13 @@ void test01()
                construct::Nontrivial>(false), "");
   static_assert(test_category<is_trivially_default_constructible, 
                HasTemplateCtor>(true), "");
+
+  static_assert(test_category<is_trivially_default_constructible,
+               int[]>(false), "PR c++/90532");
+  struct A { };
+  static_assert(test_category<is_trivially_default_constructible,
+               A[]>(false), "PR c++/90532");
+  struct B { B() { } };
+  static_assert(test_category<is_trivially_default_constructible,
+               B[]>(false), "PR c++/90532");
 }