[clang] [Clang] Fix incorrect mutability of decltype((x)) in lambda return types (PR #180690)

Younan Zhang via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 10 18:09:33 PST 2026


================
@@ -799,3 +799,16 @@ template auto t::operator()<int>(int a) const; // expected-note {{in instantiati
 
 }
 #endif
+
+namespace GH180460 {
+// Trailing return type incorrectly treated 'x' as mutable.
+void test_lambda_return_type() {
+  float x = 0.0f;
+
+  [=]() -> decltype((x)) {
+    decltype(x) y1 = x;
+    decltype((x)) y2 = y1;       // expected-note{{binding reference variable 'y2' here}}
+    return y2;                   // expected-warning{{reference to stack memory associated with local variable 'y1' returned}}
+  };
+}
+}
----------------
zyn0217 wrote:

We need an empty line here

https://github.com/llvm/llvm-project/pull/180690


More information about the cfe-commits mailing list