[PATCH] D119609: [Clang][Sema] Don't act on ReturnStmt when parsing the lambda declarator.

Jun Zhang via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 11 17:27:09 PST 2022

junaire created this revision.
junaire added reviewers: aaron.ballman, rsmith.
junaire requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Clang will try to act on ReturnStmt when parsing the lambda declarator,
which is not desirable. LambdaScopeInfo is nonnull doesn't the lambda has
been built, we should also check LambdaScopeInfo->Lambda.

Fixes #issue53488(https://github.com/llvm/llvm-project/issues/53488)

  rG LLVM Github Monorepo



Index: clang/test/Sema/returnstmt-in-lambda-declarator.cpp
--- /dev/null
+++ clang/test/Sema/returnstmt-in-lambda-declarator.cpp
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 %s -fsyntax-only -verify -std=c++11
+void g() {
+  auto f = [](char c = ({ return 42; })) {}; // expected-error {{cannot initialize a parameter of type 'char' with an rvalue of type 'void'}} expected-note {{passing argument to parameter 'c' here}}
Index: clang/lib/Sema/SemaStmt.cpp
--- clang/lib/Sema/SemaStmt.cpp
+++ clang/lib/Sema/SemaStmt.cpp
@@ -3560,6 +3560,10 @@
   CapturingScopeInfo *CurCap = cast<CapturingScopeInfo>(getCurFunction());
   QualType FnRetType = CurCap->ReturnType;
   LambdaScopeInfo *CurLambda = dyn_cast<LambdaScopeInfo>(CurCap);
+  if (CurLambda && !CurLambda->Lambda)
+    return StmtError();
   bool HasDeducedReturnType =
       CurLambda && hasDeducedReturnType(CurLambda->CallOperator);

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D119609.408126.patch
Type: text/x-patch
Size: 1032 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220212/26c84bd2/attachment.bin>

More information about the cfe-commits mailing list