[PATCH] D143109: [Sema] Push a LambdaScopeInfo before calling SubstDefaultArgument
Akira Hatanaka via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Feb 7 12:50:46 PST 2023
ahatanak updated this revision to Diff 495619.
ahatanak added a comment.
Fix indentation.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D143109/new/
https://reviews.llvm.org/D143109
Files:
clang/lib/Sema/SemaExpr.cpp
clang/test/SemaCXX/lambda-default-arg.cpp
Index: clang/test/SemaCXX/lambda-default-arg.cpp
===================================================================
--- /dev/null
+++ clang/test/SemaCXX/lambda-default-arg.cpp
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -std=c++17 -verify -fsyntax-only %s
+
+template <class T> bool test0() {
+ constexpr float a = 1e-5f;
+ return [=](float b = a) -> bool {
+ return a < 0;
+ }();
+}
+
+bool b0 = test0<int>();
+
+template <class T> bool test1() {
+ float a = 1e-5f;
+ return [=](float b = a) -> bool { // expected-error {{default argument references local variable 'a'}}
+ return a < 0;
+ }();
+}
+
+bool b1 = test1<int>();
+
+template <class T> bool test2(float a = 1e-5f) {
+ return [=](int b = sizeof(a)) -> bool {
+ return b;
+ }();
+}
+
+bool b2 = test2<int>();
Index: clang/lib/Sema/SemaExpr.cpp
===================================================================
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -19082,6 +19082,14 @@
}
}
+ // If the variable is used in a default argument expression of a lambda call
+ // operator, switch to the enclosing context to sync up with the function
+ // scope.
+ if (isLambdaCallOperator(DC))
+ if (auto *PVD = dyn_cast_or_null<ParmVarDecl>(
+ ExprEvalContexts.back().ManglingContextDecl))
+ if (PVD->getDeclContext() == DC)
+ DC = getLambdaAwareParentOfDeclContext(DC);
// If the variable is declared in the current context, there is no need to
// capture it.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D143109.495619.patch
Type: text/x-patch
Size: 1490 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230207/553700a2/attachment-0001.bin>
More information about the cfe-commits
mailing list