================ @@ -494,4 +554,75 @@ void UseTrailingReturnTypeCheck::check(const MatchFinder::MatchResult &Result) { << FixItHint::CreateInsertion(InsertionLoc, " -> " + ReturnType); } +void UseTrailingReturnTypeCheck::diagOnLambda( + const LambdaExpr *Lambda, + const ast_matchers::MatchFinder::MatchResult &Result) { + + const CXXMethodDecl *Method = Lambda->getCallOperator(); + if (!Method || Lambda->hasExplicitResultType()) + return; + + const QualType ReturnType = Method->getReturnType(); + if (ReturnType->isUndeducedAutoType() && + TransformLambdas == TransformLambda::AllExceptAuto) + return; + + const SourceLocation TrailingReturnInsertLoc = + findLambdaTrailingReturnInsertLoc(Method, *Result.SourceManager, + getLangOpts(), *Result.Context); + + if (TrailingReturnInsertLoc.isValid()) + diag(Lambda->getBeginLoc(), "use a trailing return type for this lambda") + << FixItHint::CreateInsertion( + TrailingReturnInsertLoc, + " -> " + + ReturnType.getAsString(Result.Context->getPrintingPolicy())); + else + diag(Lambda->getBeginLoc(), "use a trailing return type for this lambda"); +} + +SourceLocation UseTrailingReturnTypeCheck::findLambdaTrailingReturnInsertLoc( + const CXXMethodDecl *Method, const SourceManager &SM, + const LangOptions &LangOpts, const ASTContext &Ctx) { + // 'requires' keyword is present in lambda declaration + if (Method->getTrailingRequiresClause()) { + SourceLocation ParamEndLoc; + if (Method->param_empty()) { + ParamEndLoc = Method->getBeginLoc(); + } else { + ParamEndLoc = Method->getParametersSourceRange().getEnd(); + } + + std::pair<FileID, unsigned> ParamEndLocInfo = ---------------- vbvictor wrote:
I decided not to make generic implementation of this piece of code as for now. https://github.com/llvm/llvm-project/pull/135383 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits