]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++/reflection: template splicing tweak
authorJason Merrill <jason@redhat.com>
Wed, 3 Jun 2026 12:40:53 +0000 (08:40 -0400)
committerJason Merrill <jason@redhat.com>
Wed, 3 Jun 2026 12:40:53 +0000 (08:40 -0400)
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.

gcc/cp/parser.cc
gcc/cp/search.cc

index 6641dbba33d3a01048f7ff799ee63668c5130128..c2bcaa9739237b61ef98f3b5ed50a7bbf16f5079 100644 (file)
@@ -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))
index 5d00ce3d8260156d1b233c7200cb858b00022f60..a51fd1cd6a7593ae5ea1d47d7080c71c44ffc59d 100644 (file)
@@ -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));