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

commit r16-6886-gdb873dbcafd37a9a58cc7b26892d16336e6d0c56
Author: Marek Polacek <[email protected]>
Date:   Fri Jan 16 15:50:38 2026 -0500

    c++/reflection: adjust error message
    
    Now that the condition includes all captures, let's not talk about
    init-capture.  Also print the decl.
    
    gcc/cp/ChangeLog:
    
            * reflect.cc (get_reflection): Adjust the error message for the
            is_capture_proxy check.
    
    gcc/testsuite/ChangeLog:
    
            * g++.dg/reflect/expr6.C: Adjust dg-error.
    
    Reviewed-by: Jason Merrill <[email protected]>

Diff:
---
 gcc/cp/reflect.cc                    | 3 +--
 gcc/testsuite/g++.dg/reflect/expr6.C | 4 ++--
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/gcc/cp/reflect.cc b/gcc/cp/reflect.cc
index c2cc6948798a..c1073c59a99c 100644
--- a/gcc/cp/reflect.cc
+++ b/gcc/cp/reflect.cc
@@ -147,8 +147,7 @@ get_reflection (location_t loc, tree t, reflect_kind 
kind/*=REFLECT_UNDEF*/)
      R is ill-formed.  */
   else if (is_capture_proxy (t))
     {
-      error_at (loc, "%<^^%> cannot be applied to a local entity declared "
-               "by init-capture");
+      error_at (loc, "%<^^%> cannot be applied to a capture %qD", t);
       return error_mark_node;
     }
   /* If the id-expression denotes a local parameter introduced by
diff --git a/gcc/testsuite/g++.dg/reflect/expr6.C 
b/gcc/testsuite/g++.dg/reflect/expr6.C
index d7d0574ae88c..a2c224288dbe 100644
--- a/gcc/testsuite/g++.dg/reflect/expr6.C
+++ b/gcc/testsuite/g++.dg/reflect/expr6.C
@@ -39,11 +39,11 @@ h ()
   int y = 42;
   [x_=x, y]() {
     constexpr auto r1 = ^^x;  // { dg-error "intervening lambda expression" }
-    constexpr auto r2 = ^^x_; // { dg-error "local entity declared by 
init-capture" }
+    constexpr auto r2 = ^^x_; // { dg-error "cannot be applied to a capture 
.x_." }
     constexpr auto r3 = ^^y;  // { dg-error "intervening lambda expression" }
 
     [x_]() {
-      constexpr auto r4 = ^^x_;        // { dg-error "local entity declared by 
init-capture" }
+      constexpr auto r4 = ^^x_;        // { dg-error "cannot be applied to a 
capture .x_." }
     };
   };
 }

Reply via email to