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
| Name |
Last commit
|
Last update |
|---|---|---|
| .. | ||
| add_const | Loading commit data... | |
| add_cv | Loading commit data... | |
| add_lvalue_reference | Loading commit data... | |
| add_pointer | Loading commit data... | |
| add_rvalue_reference | Loading commit data... | |
| add_volatile | Loading commit data... | |
| addressof | Loading commit data... | |
| align | Loading commit data... | |
| aligned_storage | Loading commit data... | |
| aligned_union | Loading commit data... | |
| alignment_of | Loading commit data... | |
| allocator | Loading commit data... | |
| allocator_traits | Loading commit data... | |
| any | Loading commit data... | |
| as_const | Loading commit data... | |
| assume_aligned | Loading commit data... | |
| auto_ptr | Loading commit data... | |
| bad_function_call | Loading commit data... | |
| bind | Loading commit data... | |
| bool_constant | Loading commit data... | |
| common_type/requirements | Loading commit data... | |
| conditional/requirements | Loading commit data... | |
| decay/requirements | Loading commit data... | |
| declval/requirements | Loading commit data... | |
| default_delete | Loading commit data... | |
| duration | Loading commit data... | |
| duration_cast | Loading commit data... | |
| enable_if/requirements | Loading commit data... | |
| enable_shared_from_this | Loading commit data... | |
| endian | Loading commit data... | |
| exchange | Loading commit data... | |
| extent | Loading commit data... | |
| forward | Loading commit data... | |
| from_chars | Loading commit data... | |
| function | Loading commit data... | |
| function_objects | Loading commit data... | |
| has_unique_object_representations | Loading commit data... | |
| has_virtual_destructor | Loading commit data... | |
| hash | Loading commit data... | |
| headers | Loading commit data... | |
| in_place | Loading commit data... | |
| integer_sequence | Loading commit data... | |
| integral_constant | Loading commit data... | |
| is_abstract | Loading commit data... | |
| is_aggregate | Loading commit data... | |
| is_arithmetic | Loading commit data... | |
| is_array | Loading commit data... | |
| is_assignable | Loading commit data... | |
| is_base_of | Loading commit data... | |
| is_bounded_array | Loading commit data... | |
| is_class | Loading commit data... | |
| is_complete_or_unbounded | Loading commit data... | |
| is_compound | Loading commit data... | |
| is_const | Loading commit data... | |
| is_constant_evaluated | Loading commit data... | |
| is_constructible | Loading commit data... | |
| is_convertible | Loading commit data... | |
| is_copy_assignable | Loading commit data... | |
| is_copy_constructible | Loading commit data... | |
| is_default_constructible | Loading commit data... | |
| is_destructible | Loading commit data... | |
| is_empty | Loading commit data... | |
| is_enum | Loading commit data... | |
| is_final | Loading commit data... | |
| is_floating_point | Loading commit data... | |
| is_function | Loading commit data... | |
| is_fundamental | Loading commit data... | |
| is_implicitly_default_constructible | Loading commit data... | |
| is_integral | Loading commit data... | |
| is_invocable | Loading commit data... | |
| is_literal_type | Loading commit data... | |
| is_lvalue_reference | Loading commit data... | |
| is_member_function_pointer | Loading commit data... | |
| is_member_object_pointer | Loading commit data... | |
| is_member_pointer | Loading commit data... | |
| is_move_assignable | Loading commit data... | |
| is_move_constructible | Loading commit data... | |
| is_nothrow_assignable | Loading commit data... | |
| is_nothrow_constructible | Loading commit data... | |
| is_nothrow_convertible | Loading commit data... | |
| is_nothrow_copy_assignable | Loading commit data... | |
| is_nothrow_copy_constructible | Loading commit data... | |
| is_nothrow_default_constructible | Loading commit data... | |
| is_nothrow_destructible | Loading commit data... | |
| is_nothrow_invocable | Loading commit data... | |
| is_nothrow_move_assignable | Loading commit data... | |
| is_nothrow_move_constructible | Loading commit data... | |
| is_nothrow_swappable | Loading commit data... | |
| is_nothrow_swappable_with | Loading commit data... | |
| is_null_pointer | Loading commit data... | |
| is_object | Loading commit data... | |
| is_pod | Loading commit data... | |
| is_pointer | Loading commit data... | |
| is_polymorphic | Loading commit data... | |
| is_reference | Loading commit data... | |
| is_rvalue_reference | Loading commit data... | |
| is_same | Loading commit data... | |
| is_scalar | Loading commit data... | |
| is_signed | Loading commit data... | |
| is_standard_layout | Loading commit data... | |
| is_swappable | Loading commit data... | |
| is_swappable_with | Loading commit data... | |
| is_trivial | Loading commit data... | |
| is_trivially_assignable | Loading commit data... | |
| is_trivially_constructible | Loading commit data... | |
| is_trivially_copy_assignable | Loading commit data... | |
| is_trivially_copy_constructible | Loading commit data... | |
| is_trivially_copyable | Loading commit data... | |
| is_trivially_default_constructible | Loading commit data... | |
| is_trivially_destructible | Loading commit data... | |
| is_trivially_move_assignable | Loading commit data... | |
| is_trivially_move_constructible | Loading commit data... | |
| is_unbounded_array | Loading commit data... | |
| is_union | Loading commit data... | |
| is_unsigned | Loading commit data... | |
| is_void | Loading commit data... | |
| is_volatile | Loading commit data... | |
| logical_traits | Loading commit data... | |
| make_signed/requirements | Loading commit data... | |
| make_unsigned/requirements | Loading commit data... | |
| memory_resource | Loading commit data... | |
| monotonic_buffer_resource | Loading commit data... | |
| move | Loading commit data... | |
| move_if_noexcept | Loading commit data... | |
| nonesuch | Loading commit data... | |
| optional | Loading commit data... | |
| owner_less | Loading commit data... | |
| pair | Loading commit data... | |
| pointer_safety | Loading commit data... | |
| pointer_traits | Loading commit data... | |
| polymorphic_allocator | Loading commit data... | |
| rank | Loading commit data... | |
| ratio | Loading commit data... | |
| raw_storage_iterator | Loading commit data... | |
| reference_wrapper | Loading commit data... | |
| remove_all_extents | Loading commit data... | |
| remove_const | Loading commit data... | |
| remove_cv | Loading commit data... | |
| remove_cvref | Loading commit data... | |
| remove_extent | Loading commit data... | |
| remove_pointer | Loading commit data... | |
| remove_reference | Loading commit data... | |
| remove_volatile | Loading commit data... | |
| result_of | Loading commit data... | |
| scoped_allocator | Loading commit data... | |
| shared_ptr | Loading commit data... | |
| specialized_algorithms | Loading commit data... | |
| steady_clock | Loading commit data... | |
| synchronized_pool_resource | Loading commit data... | |
| system_clock | Loading commit data... | |
| time_point | Loading commit data... | |
| time_point_cast | Loading commit data... | |
| to_address | Loading commit data... | |
| to_chars | Loading commit data... | |
| tuple | Loading commit data... | |
| type_identity/requirements | Loading commit data... | |
| typeindex | Loading commit data... | |
| underlying_type/requirements | Loading commit data... | |
| unique_ptr | Loading commit data... | |
| unsynchronized_pool_resource | Loading commit data... | |
| unwrap_reference | Loading commit data... | |
| uses_allocator | Loading commit data... | |
| variant | Loading commit data... | |
| void_t | Loading commit data... | |
| weak_ptr | Loading commit data... | |
| rel_ops.cc | Loading commit data... | |
| temporary_buffer.cc | Loading commit data... | |
| variable_templates_for_traits.cc | Loading commit data... |