https://github.com/danix800 created https://github.com/llvm/llvm-project/pull/101031
…roto The test should be true on function with trailing return. This fixes crashes (infinite recursion) on lambda expr without parameters (without parentheses). >From 336bebf7d20feb7a6fab5ad038239b058f62bdfb Mon Sep 17 00:00:00 2001 From: dingfei <fd...@feysh.com> Date: Mon, 29 Jul 2024 23:18:20 +0800 Subject: [PATCH] [clang][ASTImporter] Fix typos in trailing return testing on lambda proto The test should be true on function with trailing return. This fixes crashes (infinite recursion) on lambda expr without parameters (without parentheses). --- clang/lib/AST/ASTImporter.cpp | 8 +++----- clang/unittests/AST/ASTImporterTest.cpp | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp index da1981d8dd05f..83aa017a00a7f 100644 --- a/clang/lib/AST/ASTImporter.cpp +++ b/clang/lib/AST/ASTImporter.cpp @@ -3665,13 +3665,10 @@ bool ASTNodeImporter::hasReturnTypeDeclaredInside(FunctionDecl *D) { const auto *FromFPT = FromTy->getAs<FunctionProtoType>(); assert(FromFPT && "Must be called on FunctionProtoType"); - auto IsCXX11LambdaWithouTrailingReturn = [&]() { + auto IsCXX11LambdaWithoutTrailingReturn = [&]() { if (Importer.FromContext.getLangOpts().CPlusPlus14) // C++14 or later return false; - if (FromFPT->hasTrailingReturn()) - return false; - if (const auto *MD = dyn_cast<CXXMethodDecl>(D)) return cast<CXXRecordDecl>(MD->getDeclContext())->isLambda(); @@ -3679,7 +3676,8 @@ bool ASTNodeImporter::hasReturnTypeDeclaredInside(FunctionDecl *D) { }; QualType RetT = FromFPT->getReturnType(); - if (isa<AutoType>(RetT.getTypePtr()) || IsCXX11LambdaWithouTrailingReturn()) { + if (FromFPT->hasTrailingReturn() || isa<AutoType>(RetT.getTypePtr()) || + IsCXX11LambdaWithoutTrailingReturn()) { FunctionDecl *Def = D->getDefinition(); IsTypeDeclaredInsideVisitor Visitor(Def ? Def : D); return Visitor.CheckType(RetT); diff --git a/clang/unittests/AST/ASTImporterTest.cpp b/clang/unittests/AST/ASTImporterTest.cpp index 57c5f79651824..d275a08dca895 100644 --- a/clang/unittests/AST/ASTImporterTest.cpp +++ b/clang/unittests/AST/ASTImporterTest.cpp @@ -6738,6 +6738,23 @@ TEST_P(ASTImporterOptionSpecificTestBase, EXPECT_TRUE(ToLambda); } +TEST_P(ASTImporterOptionSpecificTestBase, + ReturnTypeDeclaredInsideOfCXX11LambdaWithTrailingReturn) { + Decl *From, *To; + std::tie(From, To) = getImportedDecl( + R"( + void foo() { + (void) [] { + struct X {}; + return X(); + }; + } + )", + Lang_CXX11, "", Lang_CXX11, "foo"); // c++11 only + auto *ToLambda = FirstDeclMatcher<LambdaExpr>().match(To, lambdaExpr()); + EXPECT_TRUE(ToLambda); +} + TEST_P(ASTImporterOptionSpecificTestBase, LambdaInFunctionParam) { Decl *FromTU = getTuDecl( R"( _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits