diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2022-09-06 13:21:09 +0100 |
---|---|---|
committer | Jonathan Wakely <jwakely@redhat.com> | 2022-09-08 19:29:13 +0100 |
commit | 30c811f2bac73e63e0b461ba7ed3805b77898798 (patch) | |
tree | 4d3fc323d13afc3c182720d9d9ae1137ef5c1e97 /libstdc++-v3 | |
parent | 4977507e329ee3ed410fc7338b9aaada81b68361 (diff) | |
download | gcc-30c811f2bac73e63e0b461ba7ed3805b77898798.zip gcc-30c811f2bac73e63e0b461ba7ed3805b77898798.tar.gz gcc-30c811f2bac73e63e0b461ba7ed3805b77898798.tar.bz2 |
c++: Fix type completeness checks for type traits [PR106838]
The check_trait_type function is used for a number of different type
traits that have different requirements on their arguments. For example,
__is_constructible allows arrays of unknown bound even if the array
element is an incomplete type, but __is_aggregate does not, it always
requires the array element type to be complete. Other traits have
different requirements again, e.g. __is_empty allows incomplete unions,
and arrays (of known or unknown bound) of incomplete types.
This alters the check_trait_type function to take an additional KIND
parameter which indicates which set of type trait requirements to check.
As noted in a comment, the requirements for __is_aggregate deviate from
the ones for std::is_aggregate in the standard. It's not necessary for
the elements of an array to be complete types, because arrays are always
aggregates.
The type_has_virtual_destructor change is needed to avoid an ICE.
Previously it could never be called for incomplete union types as they
were (incorrectly) rejected by check_trait_type.
This change causes some additional diagnostics in some libstdc++ tests,
where the front end was not previously complaining about invalid types
that the library assertions diagnosed. We should consider removing the
library assertions from traits where the front end implements the
correct checks now.
PR c++/106838
gcc/cp/ChangeLog:
* class.cc (type_has_virtual_destructor): Return false for
union types.
* semantics.cc (check_trait_type): Add KIND parameter to support
different sets of requirements.
(finish_trait_expr): Pass KIND argument for relevant traits.
gcc/ChangeLog:
* doc/extend.texi (Type Traits): Fix requirements. Document
__is_aggregate and __is_final.
gcc/testsuite/ChangeLog:
* g++.dg/ext/array4.C: Fix invalid use of __is_constructible.
* g++.dg/ext/unary_trait_incomplete.C: Fix tests for traits with
different requirements.
libstdc++-v3/ChangeLog:
* testsuite/20_util/is_complete_or_unbounded/memoization_neg.cc:
Prune additional errors from front-end.
* testsuite/20_util/is_move_constructible/incomplete_neg.cc:
Likewise.
* testsuite/20_util/is_nothrow_swappable/incomplete_neg.cc:
Likewise.
* testsuite/20_util/is_nothrow_swappable_with/incomplete_neg.cc:
Likewise.
* testsuite/20_util/is_swappable_with/incomplete_neg.cc:
Likewise.
Diffstat (limited to 'libstdc++-v3')
5 files changed, 6 insertions, 0 deletions
diff --git a/libstdc++-v3/testsuite/20_util/is_complete_or_unbounded/memoization_neg.cc b/libstdc++-v3/testsuite/20_util/is_complete_or_unbounded/memoization_neg.cc index 1870e50..fc0b70b 100644 --- a/libstdc++-v3/testsuite/20_util/is_complete_or_unbounded/memoization_neg.cc +++ b/libstdc++-v3/testsuite/20_util/is_complete_or_unbounded/memoization_neg.cc @@ -1,5 +1,7 @@ // { dg-do compile { target c++11 } } // { dg-prune-output "must be a complete" } +// { dg-prune-output "'value' is not a member of 'std::is_move_cons" } +// { dg-prune-output "invalid use of incomplete type" } // Copyright (C) 2019-2022 Free Software Foundation, Inc. // diff --git a/libstdc++-v3/testsuite/20_util/is_move_constructible/incomplete_neg.cc b/libstdc++-v3/testsuite/20_util/is_move_constructible/incomplete_neg.cc index 7bd453d..7c34b5f 100644 --- a/libstdc++-v3/testsuite/20_util/is_move_constructible/incomplete_neg.cc +++ b/libstdc++-v3/testsuite/20_util/is_move_constructible/incomplete_neg.cc @@ -18,6 +18,7 @@ // <http://www.gnu.org/licenses/>. // { dg-error "must be a complete class" "" { target *-*-* } 0 } +// { dg-prune-output "invalid use of incomplete type" } #include <type_traits> diff --git a/libstdc++-v3/testsuite/20_util/is_nothrow_swappable/incomplete_neg.cc b/libstdc++-v3/testsuite/20_util/is_nothrow_swappable/incomplete_neg.cc index 88c9c01..d3a34cc 100644 --- a/libstdc++-v3/testsuite/20_util/is_nothrow_swappable/incomplete_neg.cc +++ b/libstdc++-v3/testsuite/20_util/is_nothrow_swappable/incomplete_neg.cc @@ -18,6 +18,7 @@ // <http://www.gnu.org/licenses/>. // { dg-error "must be a complete class" "" { target *-*-* } 0 } +// { dg-prune-output "invalid use of incomplete type" } #include <type_traits> diff --git a/libstdc++-v3/testsuite/20_util/is_nothrow_swappable_with/incomplete_neg.cc b/libstdc++-v3/testsuite/20_util/is_nothrow_swappable_with/incomplete_neg.cc index da0f771..6dfa336 100644 --- a/libstdc++-v3/testsuite/20_util/is_nothrow_swappable_with/incomplete_neg.cc +++ b/libstdc++-v3/testsuite/20_util/is_nothrow_swappable_with/incomplete_neg.cc @@ -18,6 +18,7 @@ // <http://www.gnu.org/licenses/>. // { dg-error "must be a complete class" "" { target *-*-* } 0 } +// { dg-prune-output "invalid use of incomplete type" } #include <type_traits> diff --git a/libstdc++-v3/testsuite/20_util/is_swappable_with/incomplete_neg.cc b/libstdc++-v3/testsuite/20_util/is_swappable_with/incomplete_neg.cc index 74ad291..d5fa4225 100644 --- a/libstdc++-v3/testsuite/20_util/is_swappable_with/incomplete_neg.cc +++ b/libstdc++-v3/testsuite/20_util/is_swappable_with/incomplete_neg.cc @@ -18,6 +18,7 @@ // <http://www.gnu.org/licenses/>. // { dg-error "must be a complete class" "" { target *-*-* } 0 } +// { dg-prune-output "invalid use of incomplete type" } #include <type_traits> |