@@ -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>
@@ -3666,15 +3666,28 @@ class IsTypeDeclaredInsideVisitor
3666
3666
};
3667
3667
} // namespace
3668
3668
3669
- // / This function checks if the function has 'auto' return type that contains
3669
+ // / This function checks if the given function has a return type that contains
3670
3670
// / a reference (in any way) to a declaration inside the same function.
3671
- bool ASTNodeImporter::hasAutoReturnTypeDeclaredInside (FunctionDecl *D) {
3671
+ bool ASTNodeImporter::hasReturnTypeDeclaredInside (FunctionDecl *D) {
3672
3672
QualType FromTy = D->getType ();
3673
3673
const auto *FromFPT = FromTy->getAs <FunctionProtoType>();
3674
3674
assert (FromFPT && " Must be called on FunctionProtoType" );
3675
3675
3676
+ auto IsCXX11LambdaWithouTrailingReturn = [&]() {
3677
+ if (Importer.FromContext .getLangOpts ().CPlusPlus14 ) // C++14 or later
3678
+ return false ;
3679
+
3680
+ if (FromFPT->hasTrailingReturn ())
3681
+ return false ;
3682
+
3683
+ if (const auto *MD = dyn_cast<CXXMethodDecl>(D))
3684
+ return cast<CXXRecordDecl>(MD->getDeclContext ())->isLambda ();
3685
+
3686
+ return false ;
3687
+ };
3688
+
3676
3689
QualType RetT = FromFPT->getReturnType ();
3677
- if (isa<AutoType>(RetT.getTypePtr ())) {
3690
+ if (isa<AutoType>(RetT.getTypePtr ()) || IsCXX11LambdaWithouTrailingReturn () ) {
3678
3691
FunctionDecl *Def = D->getDefinition ();
3679
3692
IsTypeDeclaredInsideVisitor Visitor (Def ? Def : D);
3680
3693
return Visitor.CheckType (RetT);
@@ -3830,7 +3843,7 @@ ExpectedDecl ASTNodeImporter::VisitFunctionDecl(FunctionDecl *D) {
3830
3843
// E.g.: auto foo() { struct X{}; return X(); }
3831
3844
// To avoid an infinite recursion when importing, create the FunctionDecl
3832
3845
// with a simplified return type.
3833
- if (hasAutoReturnTypeDeclaredInside (D)) {
3846
+ if (hasReturnTypeDeclaredInside (D)) {
3834
3847
FromReturnTy = Importer.getFromContext ().VoidTy ;
3835
3848
UsedDifferentProtoType = true ;
3836
3849
}
0 commit comments