[clang] [Clang] Diagnose function parameters used in lambda bodies in default arguments (PR #235057)
Yanzuo Liu via cfe-commits
cfe-commits at lists.llvm.org
Fri Oct 23 21:23:24 PDT 2026
================
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s
+// expected-no-diagnostics
+
+int p(int x, int = sizeof(x));
+int q(int x, int = sizeof([] { return x; }()));
+int r(int x, int = decltype([] { return x; }())());
+int s(int x, bool = noexcept([] { return x; }()));
----------------
zwuis wrote:
1. Whether or not `[] { return x; }` appears in an unevaluated context, we should reject the lambda, because using `x` requires capturing it. I'm surprised this kind of semantic checks is skipped in default arguments.
2. Same as other lambdas not in an unevaluated context, referencing function parameters should be rejected.
I'm not sure how complex the root cause might be.
https://github.com/llvm/llvm-project/pull/235057
More information about the cfe-commits
mailing list