]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: restrict TYPE_POLYMORPHIC_P to class types
authorPatrick Palka <ppalka@redhat.com>
Mon, 15 Dec 2025 20:03:36 +0000 (15:03 -0500)
committerPatrick Palka <ppalka@redhat.com>
Mon, 15 Dec 2025 20:03:36 +0000 (15:03 -0500)
commit09a9ae0dcb34ef7c57ef997f017eb5a2ddb926d4
tree4cbc8dcf0d37fecfae43bd07706c20cb22dc562c
parent381fc8ed0f1530d0c30d5dbb6119b370fd91ba68
c++: restrict TYPE_POLYMORPHIC_P to class types

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.

Reviewed-by: Jason Merrill <jason@redhat.com>
gcc/cp/cp-tree.h
gcc/cp/parser.cc
gcc/cp/rtti.cc