@@ -695,7 +695,7 @@ namespace clang {
695
695
// Returns true if the given function has a placeholder return type and
696
696
// that type is declared inside the body of the function.
697
697
// E.g. auto f() { struct X{}; return X(); }
698
- bool hasAutoReturnTypeDeclaredInside (FunctionDecl *D);
698
+ bool hasReturnTypeDeclaredInside (FunctionDecl *D);
699
699
};
700
700
701
701
template <typename InContainerTy>
@@ -3647,15 +3647,28 @@ class IsTypeDeclaredInsideVisitor
3647
3647
};
3648
3648
} // namespace
3649
3649
3650
- // / This function checks if the function has 'auto' return type that contains
3650
+ // / This function checks if the given function has a return type that contains
3651
3651
// / a reference (in any way) to a declaration inside the same function.
3652
- bool ASTNodeImporter::hasAutoReturnTypeDeclaredInside (FunctionDecl *D) {
3652
+ bool ASTNodeImporter::hasReturnTypeDeclaredInside (FunctionDecl *D) {
3653
3653
QualType FromTy = D->getType ();
3654
3654
const auto *FromFPT = FromTy->getAs <FunctionProtoType>();
3655
3655
assert (FromFPT && " Must be called on FunctionProtoType" );
3656
3656
3657
+ auto IsCXX11LambdaWithouTrailingReturn = [&]() {
3658
+ if (Importer.FromContext .getLangOpts ().CPlusPlus14 ) // C++14 or later
3659
+ return false ;
3660
+
3661
+ if (FromFPT->hasTrailingReturn ())
3662
+ return false ;
3663
+
3664
+ if (const auto *MD = dyn_cast<CXXMethodDecl>(D))
3665
+ return cast<CXXRecordDecl>(MD->getDeclContext ())->isLambda ();
3666
+
3667
+ return false ;
3668
+ };
3669
+
3657
3670
QualType RetT = FromFPT->getReturnType ();
3658
- if (isa<AutoType>(RetT.getTypePtr ())) {
3671
+ if (isa<AutoType>(RetT.getTypePtr ()) || IsCXX11LambdaWithouTrailingReturn () ) {
3659
3672
FunctionDecl *Def = D->getDefinition ();
3660
3673
IsTypeDeclaredInsideVisitor Visitor (Def ? Def : D);
3661
3674
return Visitor.CheckType (RetT);
@@ -3811,7 +3824,7 @@ ExpectedDecl ASTNodeImporter::VisitFunctionDecl(FunctionDecl *D) {
3811
3824
// E.g.: auto foo() { struct X{}; return X(); }
3812
3825
// To avoid an infinite recursion when importing, create the FunctionDecl
3813
3826
// with a simplified return type.
3814
- if (hasAutoReturnTypeDeclaredInside (D)) {
3827
+ if (hasReturnTypeDeclaredInside (D)) {
3815
3828
FromReturnTy = Importer.getFromContext ().VoidTy ;
3816
3829
UsedDifferentProtoType = true ;
3817
3830
}
0 commit comments