https://gcc.gnu.org/g:a049fa78a5f5da3f8789d8097ca8a9b69dcea9c6

commit r16-9130-ga049fa78a5f5da3f8789d8097ca8a9b69dcea9c6
Author: Marek Polacek <[email protected]>
Date:   Fri Jun 12 11:44:15 2026 -0400

    c++/reflection: ICE in get_reflection on INDIRECT_REF [PR125759]
    
    We crash here in outer_var_p on:
    
      /* These should have been stripped or otherwise handled by the caller.  */
      gcc_checking_assert (!REFERENCE_REF_P (decl));
    
    because we never stripped the INDIRECT_REF in get_reflection.  I don't
    think stripping it only for the outer_automatic_var_p call would be
    right so I'm doing it at the top of the function.
    
            PR c++/125759
    
    gcc/cp/ChangeLog:
    
            * reflect.cc (get_reflection): Do STRIP_REFERENCE_REF.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/reflect/expr17.C: New test.
    
    Reviewed-by: Patrick Palka <[email protected]>
    (cherry picked from commit d1c12591336de2358c7da4a45855ddac2e02edda)

Diff:
---
 gcc/cp/reflect.cc                     | 1 +
 gcc/testsuite/g++.dg/reflect/expr17.C | 7 +++++++
 2 files changed, 8 insertions(+)

diff --git a/gcc/cp/reflect.cc b/gcc/cp/reflect.cc
index ea4d60201ad1..1e95d3bd69f0 100644
--- a/gcc/cp/reflect.cc
+++ b/gcc/cp/reflect.cc
@@ -135,6 +135,7 @@ tree
 get_reflection (location_t loc, tree t, reflect_kind kind/*=REFLECT_UNDEF*/)
 {
   STRIP_ANY_LOCATION_WRAPPER (t);
+  t = STRIP_REFERENCE_REF (t);
 
   /* Constant template parameters and pack-index-expressions cannot
      appear as operands of the reflection operator.  */
diff --git a/gcc/testsuite/g++.dg/reflect/expr17.C 
b/gcc/testsuite/g++.dg/reflect/expr17.C
new file mode 100644
index 000000000000..6142272291d5
--- /dev/null
+++ b/gcc/testsuite/g++.dg/reflect/expr17.C
@@ -0,0 +1,7 @@
+// PR c++/125759
+// { dg-do compile { target c++26 } }
+// { dg-additional-options "-freflection" }
+
+consteval auto foo(auto&&... xs) { return (^^xs, ...); }
+constexpr auto r1 = foo (0);
+constexpr auto r2 = foo (0, 1u);

Reply via email to