-- a local entity such that there is a lambda scope that intervenes
between the expression and the point at which S was introduced"
This also checks ODR violations (reflect/odr1.C). */
- if (outer_automatic_var_p (t)
- && process_outer_var_ref (t, tf_none) == error_mark_node)
- {
- /* Not letting process_outer_var_ref emit the error so that we can
- say "in a splice expression". */
- if (complain_p)
+ if (outer_automatic_var_p (t))
+ if (tree r = process_outer_var_ref (t, tf_none))
+ if (r == error_mark_node || is_capture_proxy (r))
{
- auto_diagnostic_group d;
- error_at (loc, "use of local variable with automatic storage from "
- "containing function in a splice expression");
- inform (DECL_SOURCE_LOCATION (t), "%q#D declared here", t);
+ /* Not letting process_outer_var_ref emit the error so that we can
+ say "in a splice expression". */
+ if (complain_p)
+ {
+ auto_diagnostic_group d;
+ error_at (loc, "use of local variable with automatic storage "
+ "from containing function in a splice expression");
+ inform (DECL_SOURCE_LOCATION (t), "%q#D declared here", t);
+ }
+ return false;
}
- return false;
- }
/* If we had a reflect_kind here, we could just check for
REFLECT_ANNOTATION and be done with it. But we don't have it yet (TODO),
--- /dev/null
+// { dg-do compile { target c++26 } }
+// { dg-additional-options "-freflection" }
+
+void
+f1 ()
+{
+ int x = 1; // { dg-message ".x. declared here" }
+ constexpr auto r = ^^x;
+ [=] -> decltype(x) {
+ return [:r:]; // { dg-error "use of local variable" }
+ };
+}
+
+void
+f2 ()
+{
+ int x = 1; // { dg-message ".x. declared here" }
+ constexpr auto r = ^^x;
+ [&] -> decltype(x) {
+ return [:r:]; // { dg-error "use of local variable" }
+ };
+}