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)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D119609

Files:
  clang/lib/Sema/SemaStmt.cpp
  clang/test/Sema/returnstmt-in-lambda-declarator.cpp


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);
 


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);
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to