https://gcc.gnu.org/g:49f5c9a9b31c10f330bf0f8d804bc24633aade2b
commit r17-1260-g49f5c9a9b31c10f330bf0f8d804bc24633aade2b Author: Jason Merrill <[email protected]> Date: Wed Jun 3 08:40:53 2026 -0400 c++/reflection: template splicing tweak Discussion of the 124794 patch observed that access_path can be null if object_type isn't derived from scope, which means building a nonsensical BASELINK with null BASELINK_BINFO. PR c++/124794 gcc/cp/ChangeLog: * parser.cc (cp_parser_splice_specifier): Use TYPE_BINFO (scope) for not-derived case. * search.cc (build_baselink): Assert that binfos aren't null. Diff: --- gcc/cp/parser.cc | 10 +++++++--- gcc/cp/search.cc | 1 + 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index 6641dbba33d3..c2bcaa973923 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -6204,18 +6204,22 @@ cp_parser_splice_specifier (cp_parser *parser, bool template_p = false, tree scope = DECL_CONTEXT (expr_real); if (scope && CLASS_TYPE_P (scope)) { + /* Use the same BASELINK_BINFO and BASELINK_ACCESS_BINFO since + we don't do access checking for a splice. */ tree access_path = lookup_base (object_type, scope, ba_unique, NULL, tf_warning_or_error); + if (!access_path) + /* Not a base, access directly for the error. */ + access_path = TYPE_BINFO (scope); if (access_path == error_mark_node) expr = error_mark_node; else if (BASELINK_P (expr)) - expr = build_baselink (access_path, - BASELINK_ACCESS_BINFO (expr), + expr = build_baselink (access_path, access_path, BASELINK_FUNCTIONS (expr), BASELINK_OPTYPE (expr)); else expr - = build_baselink (access_path, TYPE_BINFO (object_type), + = build_baselink (access_path, access_path, expr, IDENTIFIER_CONV_OP_P (OVL_NAME (expr_real)) ? TREE_TYPE (OVL_NAME (expr_real)) diff --git a/gcc/cp/search.cc b/gcc/cp/search.cc index 5d00ce3d8260..a51fd1cd6a75 100644 --- a/gcc/cp/search.cc +++ b/gcc/cp/search.cc @@ -1144,6 +1144,7 @@ build_baselink (tree binfo, tree access_binfo, tree functions, tree optype) { tree baselink; + gcc_checking_assert (binfo && access_binfo); gcc_assert (OVL_P (functions) || TREE_CODE (functions) == TEMPLATE_ID_EXPR); gcc_assert (!optype || TYPE_P (optype)); gcc_assert (TREE_TYPE (functions));
