]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++/reflection: ICE with bases_of [PR125206]
authorMarek Polacek <polacek@redhat.com>
Thu, 7 May 2026 13:51:53 +0000 (09:51 -0400)
committerMarek Polacek <polacek@redhat.com>
Thu, 7 May 2026 20:38:54 +0000 (16:38 -0400)
Here we crash in strip_typedefs_expr because we recurse on a
REFLECT_EXPR with TREE_BINFO as its operand, which is not a code this
function handles.  It seems to me that we don't need to recurse for
REFLECT_EXPRs at all.  Alternatively, we could just handle TREE_BINFO.

PR c++/125206

gcc/cp/ChangeLog:

* tree.cc (strip_typedefs_expr) <case REFLECT_EXPR>: Always
return instead of recursing.

gcc/testsuite/ChangeLog:

* g++.dg/reflect/bases_of4.C: New test.

Reviewed-by: Jason Merrill <jason@redhat.com>
gcc/cp/tree.cc
gcc/testsuite/g++.dg/reflect/bases_of4.C [new file with mode: 0644]

index c510a5bf2d0b03af3c3670effb5aef583f0dd38e..2e96d65eecd74aefb1f62f39f3af6064fdf764b7 100644 (file)
@@ -2155,12 +2155,9 @@ strip_typedefs_expr (tree t, bool *remove_attributes, unsigned int flags)
 
     case LAMBDA_EXPR:
     case STMT_EXPR:
-      return t;
-
+    /* ^^alias represents the alias itself, not the underlying type.  */
     case REFLECT_EXPR:
-      /* ^^alias represents the alias itself, not the underlying type.  */
-      if (TYPE_P (REFLECT_EXPR_HANDLE (t)))
-       return t;
+      return t;
 
     default:
       break;
diff --git a/gcc/testsuite/g++.dg/reflect/bases_of4.C b/gcc/testsuite/g++.dg/reflect/bases_of4.C
new file mode 100644 (file)
index 0000000..843f0e5
--- /dev/null
@@ -0,0 +1,45 @@
+// PR c++/125206
+// { dg-do compile { target c++26 } }
+// { dg-additional-options "-freflection" }
+
+#include <meta>
+#include <type_traits>
+
+template<auto...> struct mp_list_v
+{
+};
+
+template<class...> struct mp_list
+{
+};
+
+template<auto V> using mp_value = std::integral_constant<decltype(V), V>;
+
+template<class L, template<class...> class B> struct mp_rename_impl;
+
+template<template<class...> class L, class... T, template<class...> class B> struct mp_rename_impl<L<T...>, B>
+{
+    using type = B<T...>;
+};
+
+template<template<auto...> class L, auto... A, template<class...> class B> struct mp_rename_impl<L<A...>, B>
+{
+    using type = B<mp_value<A>...>;
+};
+
+template<class L, template<class...> class B> using mp_rename = typename mp_rename_impl<L, B>::type;
+
+class X1
+{
+};
+
+class Z: public X1
+{
+};
+
+int main()
+{
+    constexpr auto all = std::meta::access_context::unchecked();
+    constexpr auto L1 = ^^mp_list_v< bases_of(^^Z, all)[0] >;
+    using L2 = mp_rename<typename [: L1 :], mp_list>;
+}