diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2019-05-20 12:32:51 +0100 |
---|---|---|
committer | Jonathan Wakely <redi@gcc.gnu.org> | 2019-05-20 12:32:51 +0100 |
commit | 58487c21b6a47c3fff6c6958684de866216a5593 (patch) | |
tree | 283b8a54c46647b461db6ecb01b894ed536af56d /gcc | |
parent | eefa592aa0b0e0ba9f144ede15389cbf7496cc64 (diff) | |
download | gcc-58487c21b6a47c3fff6c6958684de866216a5593.zip gcc-58487c21b6a47c3fff6c6958684de866216a5593.tar.gz gcc-58487c21b6a47c3fff6c6958684de866216a5593.tar.bz2 |
PR c++/90532 Ensure __is_constructible(T[]) is false
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
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/cp/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/cp/method.c | 2 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/ext/90532.C | 27 |
4 files changed, 40 insertions, 0 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 39aaab9..c8eb936 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -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 diff --git a/gcc/cp/method.c b/gcc/cp/method.c index 3fb3b5a..53fa85b 100644 --- a/gcc/cp/method.c +++ b/gcc/cp/method.c @@ -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; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 3ecff36..36db11b 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -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 index 0000000..acdc4e2 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/90532.C @@ -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), "" ); |