================
@@ -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:
This code is very alike to `findTrailingReturnTypeSourceLocation` function.
Finding the position of `requires` keyword.
https://github.com/llvm/llvm-project/pull/135383
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits