608a080c3f
This patch adds static asserts for type traits misuse with incomplete classes and unions. This gives a nice readable error message instead of an UB and odr-violations. Some features of the patch: * each type trait has it's own static_assert inside. This gives better diagnostics than the approach with putting the assert into a helper structure and using it in each trait. * the result of completeness check is not memorized by the compiler. This gives no false positive after the first failed check. * some of the compiler builtins already implement the check. But not all of them! So the asserts are in all the type_traits that may benefit from the check. This also makes the behavior of libstdc++ more consistent across different (non GCC) compilers. * std::is_base_of does not have the assert as it works well in many cases with incomplete types 2019-05-31 Antony Polukhin <antoshkka@gmail.com> PR libstdc++/71579 * include/std/type_traits __type_identity, __is_complete_or_unbounded): New helpers for checking preconditions in traits. (is_trivial, is_trivially_copyable, is_standard_layout, is_pod) (is_literal_type, is_empty, is_polymorphic, is_final, is_abstract) (is_destructible, is_nothrow_destructible, is_constructible) (is_default_constructible, is_copy_constructible) (is_move_constructible, is_nothrow_default_constructible) (is_nothrow_constructible, is_nothrow_copy_constructible) (is_nothrow_move_constructible, is_copy_assignable, is_move_assignable) (is_nothrow_assignable, is_nothrow_copy_assignable) (is_nothrow_move_assignable, is_trivially_constructible) (is_trivially_copy_constructible, is_trivially_move_constructible) is_trivially_assignable, is_trivially_copy_assignable) (is_trivially_move_assignable, is_trivially_destructible) (alignment_of, is_swappable, is_nothrow_swappable, is_invocable) (is_invocable_r, is_nothrow_invocable) (has_unique_object_representations, is_aggregate): Add static_asserts to make sure that type traits are not misused with incomplete types. (__is_constructible_impl, __is_nothrow_default_constructible_impl) (__is_nothrow_constructible_impl, __is_nothrow_assignable_impl): New base characteristics without assertions that can be reused in other traits. * testsuite/20_util/is_complete_or_unbounded/memoization.cc: New test. * testsuite/20_util/is_complete_or_unbounded/memoization_neg.cc: New test. * testsuite/20_util/is_complete_or_unbounded/value.cc: New test. * testsuite/20_util/is_abstract/incomplete_neg.cc: New test. * testsuite/20_util/is_aggregate/incomplete_neg.cc: New test. * testsuite/20_util/is_class/value.cc: Check incomplete type. * testsuite/20_util/is_function/value.cc: Likewise. * testsuite/20_util/is_move_constructible/incomplete_neg.cc: New test. * testsuite/20_util/is_nothrow_move_assignable/incomplete_neg.cc: New test. * testsuite/20_util/is_polymorphic/incomplete_neg.cc: New test. * testsuite/20_util/is_reference/value.cc: Check incomplete types. * testsuite/20_util/is_unbounded_array/value.cc: Likewise. * testsuite/20_util/is_union/value.cc: Likewise. * testsuite/20_util/is_void/value.cc: Likewise. * testsuite/util/testsuite_tr1.h: Add incomplete union type. From-SVN: r271806 |
||
---|---|---|
.. | ||
common_type | ||
debug | ||
exception | ||
hash_fn | ||
io | ||
native_type | ||
performance | ||
pstl | ||
regression | ||
statistic | ||
thread | ||
replacement_memory_operators.h | ||
specfun_testcase.h | ||
testsuite_abi_check.cc | ||
testsuite_abi.cc | ||
testsuite_abi.h | ||
testsuite_allocator.cc | ||
testsuite_allocator.h | ||
testsuite_api.h | ||
testsuite_character.cc | ||
testsuite_character.h | ||
testsuite_common_types.h | ||
testsuite_container_traits.h | ||
testsuite_containergen.h | ||
testsuite_containers.h | ||
testsuite_counter_type.h | ||
testsuite_error.h | ||
testsuite_fs.h | ||
testsuite_greedy_ops.h | ||
testsuite_hooks.cc | ||
testsuite_hooks.h | ||
testsuite_io.h | ||
testsuite_iterators.h | ||
testsuite_new_operators.h | ||
testsuite_performance.h | ||
testsuite_random.h | ||
testsuite_regex.h | ||
testsuite_rng.h | ||
testsuite_rvalref.h | ||
testsuite_shared.cc | ||
testsuite_tr1.h |