Since TYPE_POLYMORPHIC_P shares the same storage as other flags for
TYPENAME_TYPE and DECLTYPE_TYPE, we should avoid accidentally using
this accessor on those tree codes. This patch restricts the accessor
to RECORD/UNION_TYPE which allows callers to conveniently guard any
uses with CLASS_TYPE_P. Otherwise with the next patch applied that
rearranges TYPENAME_TYPE flags, noexcept_override_late_checks would
not skip over a TYPENAME_TYPE base for which TYPE_POLYMORPHIC_P
nonsensically returns true, leading to an eventual ICE.
gcc/cp/ChangeLog:
* cp-tree.h (CLASSTYPE_LAMBDA_EXPR): Check CLASS_TYPE_P before
inspecting TYPE_POLYMORPHIC_P.
(TYPE_POLYMORPHIC_P): Restrict to RECORD_TYPE or UNION_TYPE.
Document its use of TREE_LANG_FLAG_2.
* parser.cc (noexcept_override_late_checks): Only
check TYPE_POLYMORPHIC_P on CLASS_TYPE_P types.
* rtti.cc (build_headof): Likewise.
(get_tinfo_ptr_dynamic): Likewise.
(build_typeid): Likewise.