[clang-tools-extra] [clang-tidy][NFC] Refactor `modernize-use-trailing-return-type-check` check code and tests (PR #140759)

2025-05-24 Thread Baranov Victor via cfe-commits

https://github.com/vbvictor closed 
https://github.com/llvm/llvm-project/pull/140759
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy][NFC] Refactor `modernize-use-trailing-return-type-check` check code and tests (PR #140759)

2025-05-21 Thread Carlos Galvez via cfe-commits

https://github.com/carlosgalvezp approved this pull request.

LGTM!

https://github.com/llvm/llvm-project/pull/140759
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy][NFC] Refactor `modernize-use-trailing-return-type-check` check code and tests (PR #140759)

2025-05-21 Thread Carlos Galvez via cfe-commits


@@ -113,7 +113,7 @@ struct UnqualNameVisitor : public 
RecursiveASTVisitor {
 };
 } // namespace
 
-constexpr llvm::StringLiteral Message =
+constexpr llvm::StringLiteral MessageFunction =

carlosgalvezp wrote:

Ok! I think this change would have been better to do in #135383, where it 
clearly shows that you need 2 different error messages. 

https://github.com/llvm/llvm-project/pull/140759
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy][NFC] Refactor `modernize-use-trailing-return-type-check` check code and tests (PR #140759)

2025-05-21 Thread Nicolas van Kempen via cfe-commits


@@ -39,23 +38,6 @@ class UseTrailingReturnTypeCheck : public ClangTidyCheck {
 
 private:
   Preprocessor *PP = nullptr;

nicovank wrote:

Is this field still needed now?

https://github.com/llvm/llvm-project/pull/140759
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy][NFC] Refactor `modernize-use-trailing-return-type-check` check code and tests (PR #140759)

2025-05-20 Thread Baranov Victor via cfe-commits


@@ -28,7 +27,7 @@ struct ClassifiedToken {
 class UseTrailingReturnTypeCheck : public ClangTidyCheck {
 public:
   UseTrailingReturnTypeCheck(StringRef Name, ClangTidyContext *Context)
-  : ClangTidyCheck(Name, Context) {}
+  : ClangTidyCheck(Name, Context) {};

vbvictor wrote:

Overlooked, fixed now

https://github.com/llvm/llvm-project/pull/140759
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy][NFC] Refactor `modernize-use-trailing-return-type-check` check code and tests (PR #140759)

2025-05-20 Thread Baranov Victor via cfe-commits

https://github.com/vbvictor updated 
https://github.com/llvm/llvm-project/pull/140759

>From fbae463925738d8628593d5daaabe2a299aecbbf Mon Sep 17 00:00:00 2001
From: Baranov Victor 
Date: Tue, 20 May 2025 19:23:35 +0300
Subject: [PATCH 1/4] [clang-tidy][nfc] refactor use-trailing-return-type-check
 private methods to be static functions and fix styling issues

---
 .../modernize/UseTrailingReturnTypeCheck.cpp  | 65 ++-
 .../modernize/UseTrailingReturnTypeCheck.h| 21 +-
 .../use-trailing-return-type-cxx20.cpp|  2 +-
 3 files changed, 37 insertions(+), 51 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp
index 9774e988d71e2..d90876d59a6ad 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp
@@ -113,7 +113,7 @@ struct UnqualNameVisitor : public 
RecursiveASTVisitor {
 };
 } // namespace
 
-constexpr llvm::StringLiteral Message =
+constexpr llvm::StringLiteral MessageFunction =
 "use a trailing return type for this function";
 
 static SourceLocation expandIfMacroId(SourceLocation Loc,
@@ -125,7 +125,7 @@ static SourceLocation expandIfMacroId(SourceLocation Loc,
   return Loc;
 }
 
-SourceLocation 
UseTrailingReturnTypeCheck::findTrailingReturnTypeSourceLocation(
+static SourceLocation findTrailingReturnTypeSourceLocation(
 const FunctionDecl &F, const FunctionTypeLoc &FTL, const ASTContext &Ctx,
 const SourceManager &SM, const LangOptions &LangOpts) {
   // We start with the location of the closing parenthesis.
@@ -217,10 +217,11 @@ classifyToken(const FunctionDecl &F, Preprocessor &PP, 
Token Tok) {
   return CT;
 }
 
-std::optional>
-UseTrailingReturnTypeCheck::classifyTokensBeforeFunctionName(
-const FunctionDecl &F, const ASTContext &Ctx, const SourceManager &SM,
-const LangOptions &LangOpts) {
+static std::optional>
+classifyTokensBeforeFunctionName(const FunctionDecl &F, const ASTContext &Ctx,
+ const SourceManager &SM,
+ const LangOptions &LangOpts,
+ Preprocessor *PP) {
   SourceLocation BeginF = expandIfMacroId(F.getBeginLoc(), SM);
   SourceLocation BeginNameF = expandIfMacroId(F.getLocation(), SM);
 
@@ -242,7 +243,6 @@ 
UseTrailingReturnTypeCheck::classifyTokensBeforeFunctionName(
 const MacroInfo *MI = PP->getMacroInfo(&Info);
 if (!MI || MI->isFunctionLike()) {
   // Cannot handle function style macros.
-  diag(F.getLocation(), Message);
   return std::nullopt;
 }
   }
@@ -253,10 +253,8 @@ 
UseTrailingReturnTypeCheck::classifyTokensBeforeFunctionName(
 
 if (std::optional CT = classifyToken(F, *PP, T))
   ClassifiedTokens.push_back(*CT);
-else {
-  diag(F.getLocation(), Message);
+else
   return std::nullopt;
-}
   }
 
   return ClassifiedTokens;
@@ -273,9 +271,10 @@ static bool hasAnyNestedLocalQualifiers(QualType Type) {
   return Result;
 }
 
-SourceRange UseTrailingReturnTypeCheck::findReturnTypeAndCVSourceRange(
-const FunctionDecl &F, const TypeLoc &ReturnLoc, const ASTContext &Ctx,
-const SourceManager &SM, const LangOptions &LangOpts) {
+static SourceRange
+findReturnTypeAndCVSourceRange(const FunctionDecl &F, const TypeLoc &ReturnLoc,
+   const ASTContext &Ctx, const SourceManager &SM,
+   const LangOptions &LangOpts, Preprocessor *PP) {
 
   // We start with the range of the return type and expand to neighboring
   // qualifiers (const, volatile and restrict).
@@ -283,7 +282,6 @@ SourceRange 
UseTrailingReturnTypeCheck::findReturnTypeAndCVSourceRange(
   if (ReturnTypeRange.isInvalid()) {
 // Happens if e.g. clang cannot resolve all includes and the return type is
 // unknown.
-diag(F.getLocation(), Message);
 return {};
   }
 
@@ -294,7 +292,7 @@ SourceRange 
UseTrailingReturnTypeCheck::findReturnTypeAndCVSourceRange(
 
   // Include qualifiers to the left and right of the return type.
   std::optional> MaybeTokens =
-  classifyTokensBeforeFunctionName(F, Ctx, SM, LangOpts);
+  classifyTokensBeforeFunctionName(F, Ctx, SM, LangOpts, PP);
   if (!MaybeTokens)
 return {};
   const SmallVector &Tokens = *MaybeTokens;
@@ -331,10 +329,11 @@ SourceRange 
UseTrailingReturnTypeCheck::findReturnTypeAndCVSourceRange(
   return ReturnTypeRange;
 }
 
-void UseTrailingReturnTypeCheck::keepSpecifiers(
-std::string &ReturnType, std::string &Auto, SourceRange ReturnTypeCVRange,
-const FunctionDecl &F, const FriendDecl *Fr, const ASTContext &Ctx,
-const SourceManager &SM, const LangOptions &LangOpts) {
+static void keepSpecifiers(std::string &ReturnType, std::string &Auto,
+   SourceRange ReturnTypeCVRange, const FunctionDecl 
&F,

[clang-tools-extra] [clang-tidy][NFC] Refactor `modernize-use-trailing-return-type-check` check code and tests (PR #140759)

2025-05-20 Thread Baranov Victor via cfe-commits


@@ -28,7 +27,7 @@ struct ClassifiedToken {
 class UseTrailingReturnTypeCheck : public ClangTidyCheck {
 public:
   UseTrailingReturnTypeCheck(StringRef Name, ClangTidyContext *Context)
-  : ClangTidyCheck(Name, Context) {}
+  : ClangTidyCheck(Name, Context) {};

vbvictor wrote:

```suggestion
  : ClangTidyCheck(Name, Context) {}
```


https://github.com/llvm/llvm-project/pull/140759
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy][NFC] Refactor `modernize-use-trailing-return-type-check` check code and tests (PR #140759)

2025-05-20 Thread Nicolas van Kempen via cfe-commits

https://github.com/nicovank edited 
https://github.com/llvm/llvm-project/pull/140759
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy][NFC] Refactor `modernize-use-trailing-return-type-check` check code and tests (PR #140759)

2025-05-20 Thread Nicolas van Kempen via cfe-commits


@@ -28,7 +27,7 @@ struct ClassifiedToken {
 class UseTrailingReturnTypeCheck : public ClangTidyCheck {
 public:
   UseTrailingReturnTypeCheck(StringRef Name, ClangTidyContext *Context)
-  : ClangTidyCheck(Name, Context) {}
+  : ClangTidyCheck(Name, Context) {};

nicovank wrote:

Is there a need for this semicolon?

https://github.com/llvm/llvm-project/pull/140759
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy][NFC] Refactor `modernize-use-trailing-return-type-check` check code and tests (PR #140759)

2025-05-20 Thread Baranov Victor via cfe-commits

https://github.com/vbvictor updated 
https://github.com/llvm/llvm-project/pull/140759

>From fbae463925738d8628593d5daaabe2a299aecbbf Mon Sep 17 00:00:00 2001
From: Baranov Victor 
Date: Tue, 20 May 2025 19:23:35 +0300
Subject: [PATCH 1/3] [clang-tidy][nfc] refactor use-trailing-return-type-check
 private methods to be static functions and fix styling issues

---
 .../modernize/UseTrailingReturnTypeCheck.cpp  | 65 ++-
 .../modernize/UseTrailingReturnTypeCheck.h| 21 +-
 .../use-trailing-return-type-cxx20.cpp|  2 +-
 3 files changed, 37 insertions(+), 51 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp
index 9774e988d71e2..d90876d59a6ad 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp
@@ -113,7 +113,7 @@ struct UnqualNameVisitor : public 
RecursiveASTVisitor {
 };
 } // namespace
 
-constexpr llvm::StringLiteral Message =
+constexpr llvm::StringLiteral MessageFunction =
 "use a trailing return type for this function";
 
 static SourceLocation expandIfMacroId(SourceLocation Loc,
@@ -125,7 +125,7 @@ static SourceLocation expandIfMacroId(SourceLocation Loc,
   return Loc;
 }
 
-SourceLocation 
UseTrailingReturnTypeCheck::findTrailingReturnTypeSourceLocation(
+static SourceLocation findTrailingReturnTypeSourceLocation(
 const FunctionDecl &F, const FunctionTypeLoc &FTL, const ASTContext &Ctx,
 const SourceManager &SM, const LangOptions &LangOpts) {
   // We start with the location of the closing parenthesis.
@@ -217,10 +217,11 @@ classifyToken(const FunctionDecl &F, Preprocessor &PP, 
Token Tok) {
   return CT;
 }
 
-std::optional>
-UseTrailingReturnTypeCheck::classifyTokensBeforeFunctionName(
-const FunctionDecl &F, const ASTContext &Ctx, const SourceManager &SM,
-const LangOptions &LangOpts) {
+static std::optional>
+classifyTokensBeforeFunctionName(const FunctionDecl &F, const ASTContext &Ctx,
+ const SourceManager &SM,
+ const LangOptions &LangOpts,
+ Preprocessor *PP) {
   SourceLocation BeginF = expandIfMacroId(F.getBeginLoc(), SM);
   SourceLocation BeginNameF = expandIfMacroId(F.getLocation(), SM);
 
@@ -242,7 +243,6 @@ 
UseTrailingReturnTypeCheck::classifyTokensBeforeFunctionName(
 const MacroInfo *MI = PP->getMacroInfo(&Info);
 if (!MI || MI->isFunctionLike()) {
   // Cannot handle function style macros.
-  diag(F.getLocation(), Message);
   return std::nullopt;
 }
   }
@@ -253,10 +253,8 @@ 
UseTrailingReturnTypeCheck::classifyTokensBeforeFunctionName(
 
 if (std::optional CT = classifyToken(F, *PP, T))
   ClassifiedTokens.push_back(*CT);
-else {
-  diag(F.getLocation(), Message);
+else
   return std::nullopt;
-}
   }
 
   return ClassifiedTokens;
@@ -273,9 +271,10 @@ static bool hasAnyNestedLocalQualifiers(QualType Type) {
   return Result;
 }
 
-SourceRange UseTrailingReturnTypeCheck::findReturnTypeAndCVSourceRange(
-const FunctionDecl &F, const TypeLoc &ReturnLoc, const ASTContext &Ctx,
-const SourceManager &SM, const LangOptions &LangOpts) {
+static SourceRange
+findReturnTypeAndCVSourceRange(const FunctionDecl &F, const TypeLoc &ReturnLoc,
+   const ASTContext &Ctx, const SourceManager &SM,
+   const LangOptions &LangOpts, Preprocessor *PP) {
 
   // We start with the range of the return type and expand to neighboring
   // qualifiers (const, volatile and restrict).
@@ -283,7 +282,6 @@ SourceRange 
UseTrailingReturnTypeCheck::findReturnTypeAndCVSourceRange(
   if (ReturnTypeRange.isInvalid()) {
 // Happens if e.g. clang cannot resolve all includes and the return type is
 // unknown.
-diag(F.getLocation(), Message);
 return {};
   }
 
@@ -294,7 +292,7 @@ SourceRange 
UseTrailingReturnTypeCheck::findReturnTypeAndCVSourceRange(
 
   // Include qualifiers to the left and right of the return type.
   std::optional> MaybeTokens =
-  classifyTokensBeforeFunctionName(F, Ctx, SM, LangOpts);
+  classifyTokensBeforeFunctionName(F, Ctx, SM, LangOpts, PP);
   if (!MaybeTokens)
 return {};
   const SmallVector &Tokens = *MaybeTokens;
@@ -331,10 +329,11 @@ SourceRange 
UseTrailingReturnTypeCheck::findReturnTypeAndCVSourceRange(
   return ReturnTypeRange;
 }
 
-void UseTrailingReturnTypeCheck::keepSpecifiers(
-std::string &ReturnType, std::string &Auto, SourceRange ReturnTypeCVRange,
-const FunctionDecl &F, const FriendDecl *Fr, const ASTContext &Ctx,
-const SourceManager &SM, const LangOptions &LangOpts) {
+static void keepSpecifiers(std::string &ReturnType, std::string &Auto,
+   SourceRange ReturnTypeCVRange, const FunctionDecl 
&F,

[clang-tools-extra] [clang-tidy][NFC] Refactor `modernize-use-trailing-return-type-check` check code and tests (PR #140759)

2025-05-20 Thread Baranov Victor via cfe-commits

https://github.com/vbvictor updated 
https://github.com/llvm/llvm-project/pull/140759

>From fbae463925738d8628593d5daaabe2a299aecbbf Mon Sep 17 00:00:00 2001
From: Baranov Victor 
Date: Tue, 20 May 2025 19:23:35 +0300
Subject: [PATCH 1/2] [clang-tidy][nfc] refactor use-trailing-return-type-check
 private methods to be static functions and fix styling issues

---
 .../modernize/UseTrailingReturnTypeCheck.cpp  | 65 ++-
 .../modernize/UseTrailingReturnTypeCheck.h| 21 +-
 .../use-trailing-return-type-cxx20.cpp|  2 +-
 3 files changed, 37 insertions(+), 51 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp
index 9774e988d71e2..d90876d59a6ad 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp
@@ -113,7 +113,7 @@ struct UnqualNameVisitor : public 
RecursiveASTVisitor {
 };
 } // namespace
 
-constexpr llvm::StringLiteral Message =
+constexpr llvm::StringLiteral MessageFunction =
 "use a trailing return type for this function";
 
 static SourceLocation expandIfMacroId(SourceLocation Loc,
@@ -125,7 +125,7 @@ static SourceLocation expandIfMacroId(SourceLocation Loc,
   return Loc;
 }
 
-SourceLocation 
UseTrailingReturnTypeCheck::findTrailingReturnTypeSourceLocation(
+static SourceLocation findTrailingReturnTypeSourceLocation(
 const FunctionDecl &F, const FunctionTypeLoc &FTL, const ASTContext &Ctx,
 const SourceManager &SM, const LangOptions &LangOpts) {
   // We start with the location of the closing parenthesis.
@@ -217,10 +217,11 @@ classifyToken(const FunctionDecl &F, Preprocessor &PP, 
Token Tok) {
   return CT;
 }
 
-std::optional>
-UseTrailingReturnTypeCheck::classifyTokensBeforeFunctionName(
-const FunctionDecl &F, const ASTContext &Ctx, const SourceManager &SM,
-const LangOptions &LangOpts) {
+static std::optional>
+classifyTokensBeforeFunctionName(const FunctionDecl &F, const ASTContext &Ctx,
+ const SourceManager &SM,
+ const LangOptions &LangOpts,
+ Preprocessor *PP) {
   SourceLocation BeginF = expandIfMacroId(F.getBeginLoc(), SM);
   SourceLocation BeginNameF = expandIfMacroId(F.getLocation(), SM);
 
@@ -242,7 +243,6 @@ 
UseTrailingReturnTypeCheck::classifyTokensBeforeFunctionName(
 const MacroInfo *MI = PP->getMacroInfo(&Info);
 if (!MI || MI->isFunctionLike()) {
   // Cannot handle function style macros.
-  diag(F.getLocation(), Message);
   return std::nullopt;
 }
   }
@@ -253,10 +253,8 @@ 
UseTrailingReturnTypeCheck::classifyTokensBeforeFunctionName(
 
 if (std::optional CT = classifyToken(F, *PP, T))
   ClassifiedTokens.push_back(*CT);
-else {
-  diag(F.getLocation(), Message);
+else
   return std::nullopt;
-}
   }
 
   return ClassifiedTokens;
@@ -273,9 +271,10 @@ static bool hasAnyNestedLocalQualifiers(QualType Type) {
   return Result;
 }
 
-SourceRange UseTrailingReturnTypeCheck::findReturnTypeAndCVSourceRange(
-const FunctionDecl &F, const TypeLoc &ReturnLoc, const ASTContext &Ctx,
-const SourceManager &SM, const LangOptions &LangOpts) {
+static SourceRange
+findReturnTypeAndCVSourceRange(const FunctionDecl &F, const TypeLoc &ReturnLoc,
+   const ASTContext &Ctx, const SourceManager &SM,
+   const LangOptions &LangOpts, Preprocessor *PP) {
 
   // We start with the range of the return type and expand to neighboring
   // qualifiers (const, volatile and restrict).
@@ -283,7 +282,6 @@ SourceRange 
UseTrailingReturnTypeCheck::findReturnTypeAndCVSourceRange(
   if (ReturnTypeRange.isInvalid()) {
 // Happens if e.g. clang cannot resolve all includes and the return type is
 // unknown.
-diag(F.getLocation(), Message);
 return {};
   }
 
@@ -294,7 +292,7 @@ SourceRange 
UseTrailingReturnTypeCheck::findReturnTypeAndCVSourceRange(
 
   // Include qualifiers to the left and right of the return type.
   std::optional> MaybeTokens =
-  classifyTokensBeforeFunctionName(F, Ctx, SM, LangOpts);
+  classifyTokensBeforeFunctionName(F, Ctx, SM, LangOpts, PP);
   if (!MaybeTokens)
 return {};
   const SmallVector &Tokens = *MaybeTokens;
@@ -331,10 +329,11 @@ SourceRange 
UseTrailingReturnTypeCheck::findReturnTypeAndCVSourceRange(
   return ReturnTypeRange;
 }
 
-void UseTrailingReturnTypeCheck::keepSpecifiers(
-std::string &ReturnType, std::string &Auto, SourceRange ReturnTypeCVRange,
-const FunctionDecl &F, const FriendDecl *Fr, const ASTContext &Ctx,
-const SourceManager &SM, const LangOptions &LangOpts) {
+static void keepSpecifiers(std::string &ReturnType, std::string &Auto,
+   SourceRange ReturnTypeCVRange, const FunctionDecl 
&F,

[clang-tools-extra] [clang-tidy][NFC] Refactor `modernize-use-trailing-return-type-check` check code and tests (PR #140759)

2025-05-20 Thread Baranov Victor via cfe-commits


@@ -113,7 +113,7 @@ struct UnqualNameVisitor : public 
RecursiveASTVisitor {
 };
 } // namespace
 
-constexpr llvm::StringLiteral Message =
+constexpr llvm::StringLiteral MessageFunction =

vbvictor wrote:

This came from https://github.com/llvm/llvm-project/pull/135383, I will need a 
second error message for lambdas. Maybe it's better to write 
`ErrorMessageOnFunction` and `ErrorMessageOnLambda` or `MessageOnFunction` and 
`MessageOnLambda` for short.

https://github.com/llvm/llvm-project/pull/140759
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy][NFC] Refactor `modernize-use-trailing-return-type-check` check code and tests (PR #140759)

2025-05-20 Thread Baranov Victor via cfe-commits


@@ -383,6 +382,10 @@ void UseTrailingReturnTypeCheck::keepSpecifiers(
   }
 }
 
+UseTrailingReturnTypeCheck::UseTrailingReturnTypeCheck(

vbvictor wrote:

Initially, I did this change in preparation for PR 
https://github.com/llvm/llvm-project/pull/135383, where I added 2 options and 
move Ctor to .cpp file.
I'll revert this and do only obvious changes in NFC in the future to avoid 
confusion

https://github.com/llvm/llvm-project/pull/140759
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy][NFC] Refactor `modernize-use-trailing-return-type-check` check code and tests (PR #140759)

2025-05-20 Thread Carlos Galvez via cfe-commits


@@ -383,6 +382,10 @@ void UseTrailingReturnTypeCheck::keepSpecifiers(
   }
 }
 
+UseTrailingReturnTypeCheck::UseTrailingReturnTypeCheck(

carlosgalvezp wrote:

Nit: typically we keep these in the header in this case, since it's just 1 more 
line in the header, compared to 3 more lines in the .cpp.

https://github.com/llvm/llvm-project/pull/140759
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy][NFC] Refactor `modernize-use-trailing-return-type-check` check code and tests (PR #140759)

2025-05-20 Thread Carlos Galvez via cfe-commits


@@ -113,7 +113,7 @@ struct UnqualNameVisitor : public 
RecursiveASTVisitor {
 };
 } // namespace
 
-constexpr llvm::StringLiteral Message =
+constexpr llvm::StringLiteral MessageFunction =

carlosgalvezp wrote:

Nit: I think the name was clearer before. I read this as "the function that 
does something with the message". 

Maybe `ErrorMessage` would be more accurate?

https://github.com/llvm/llvm-project/pull/140759
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy][NFC] Refactor `modernize-use-trailing-return-type-check` check code and tests (PR #140759)

2025-05-20 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tools-extra

Author: Baranov Victor (vbvictor)


Changes

- Deleted unused includes
- Deleted useless braces
- Converted private methods to static function to improve compilations speed 
and readability
- Modernized tests to use `cxx-or-later` 

---
Full diff: https://github.com/llvm/llvm-project/pull/140759.diff


3 Files Affected:

- (modified) 
clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp (+35-30) 
- (modified) 
clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.h (+1-20) 
- (modified) 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-trailing-return-type-cxx20.cpp
 (+1-1) 


``diff
diff --git 
a/clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp
index 9774e988d71e2..d90876d59a6ad 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp
@@ -113,7 +113,7 @@ struct UnqualNameVisitor : public 
RecursiveASTVisitor {
 };
 } // namespace
 
-constexpr llvm::StringLiteral Message =
+constexpr llvm::StringLiteral MessageFunction =
 "use a trailing return type for this function";
 
 static SourceLocation expandIfMacroId(SourceLocation Loc,
@@ -125,7 +125,7 @@ static SourceLocation expandIfMacroId(SourceLocation Loc,
   return Loc;
 }
 
-SourceLocation 
UseTrailingReturnTypeCheck::findTrailingReturnTypeSourceLocation(
+static SourceLocation findTrailingReturnTypeSourceLocation(
 const FunctionDecl &F, const FunctionTypeLoc &FTL, const ASTContext &Ctx,
 const SourceManager &SM, const LangOptions &LangOpts) {
   // We start with the location of the closing parenthesis.
@@ -217,10 +217,11 @@ classifyToken(const FunctionDecl &F, Preprocessor &PP, 
Token Tok) {
   return CT;
 }
 
-std::optional>
-UseTrailingReturnTypeCheck::classifyTokensBeforeFunctionName(
-const FunctionDecl &F, const ASTContext &Ctx, const SourceManager &SM,
-const LangOptions &LangOpts) {
+static std::optional>
+classifyTokensBeforeFunctionName(const FunctionDecl &F, const ASTContext &Ctx,
+ const SourceManager &SM,
+ const LangOptions &LangOpts,
+ Preprocessor *PP) {
   SourceLocation BeginF = expandIfMacroId(F.getBeginLoc(), SM);
   SourceLocation BeginNameF = expandIfMacroId(F.getLocation(), SM);
 
@@ -242,7 +243,6 @@ 
UseTrailingReturnTypeCheck::classifyTokensBeforeFunctionName(
 const MacroInfo *MI = PP->getMacroInfo(&Info);
 if (!MI || MI->isFunctionLike()) {
   // Cannot handle function style macros.
-  diag(F.getLocation(), Message);
   return std::nullopt;
 }
   }
@@ -253,10 +253,8 @@ 
UseTrailingReturnTypeCheck::classifyTokensBeforeFunctionName(
 
 if (std::optional CT = classifyToken(F, *PP, T))
   ClassifiedTokens.push_back(*CT);
-else {
-  diag(F.getLocation(), Message);
+else
   return std::nullopt;
-}
   }
 
   return ClassifiedTokens;
@@ -273,9 +271,10 @@ static bool hasAnyNestedLocalQualifiers(QualType Type) {
   return Result;
 }
 
-SourceRange UseTrailingReturnTypeCheck::findReturnTypeAndCVSourceRange(
-const FunctionDecl &F, const TypeLoc &ReturnLoc, const ASTContext &Ctx,
-const SourceManager &SM, const LangOptions &LangOpts) {
+static SourceRange
+findReturnTypeAndCVSourceRange(const FunctionDecl &F, const TypeLoc &ReturnLoc,
+   const ASTContext &Ctx, const SourceManager &SM,
+   const LangOptions &LangOpts, Preprocessor *PP) {
 
   // We start with the range of the return type and expand to neighboring
   // qualifiers (const, volatile and restrict).
@@ -283,7 +282,6 @@ SourceRange 
UseTrailingReturnTypeCheck::findReturnTypeAndCVSourceRange(
   if (ReturnTypeRange.isInvalid()) {
 // Happens if e.g. clang cannot resolve all includes and the return type is
 // unknown.
-diag(F.getLocation(), Message);
 return {};
   }
 
@@ -294,7 +292,7 @@ SourceRange 
UseTrailingReturnTypeCheck::findReturnTypeAndCVSourceRange(
 
   // Include qualifiers to the left and right of the return type.
   std::optional> MaybeTokens =
-  classifyTokensBeforeFunctionName(F, Ctx, SM, LangOpts);
+  classifyTokensBeforeFunctionName(F, Ctx, SM, LangOpts, PP);
   if (!MaybeTokens)
 return {};
   const SmallVector &Tokens = *MaybeTokens;
@@ -331,10 +329,11 @@ SourceRange 
UseTrailingReturnTypeCheck::findReturnTypeAndCVSourceRange(
   return ReturnTypeRange;
 }
 
-void UseTrailingReturnTypeCheck::keepSpecifiers(
-std::string &ReturnType, std::string &Auto, SourceRange ReturnTypeCVRange,
-const FunctionDecl &F, const FriendDecl *Fr, const ASTContext &Ctx,
-const SourceManager &SM, const LangOptions &LangOpts) {
+static void keepSpecifiers(std::string &ReturnType, std::string

[clang-tools-extra] [clang-tidy][NFC] Refactor `modernize-use-trailing-return-type-check` check code and tests (PR #140759)

2025-05-20 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tidy

Author: Baranov Victor (vbvictor)


Changes

- Deleted unused includes
- Deleted useless braces
- Converted private methods to static function to improve compilations speed 
and readability
- Modernized tests to use `cxx-or-later` 

---
Full diff: https://github.com/llvm/llvm-project/pull/140759.diff


3 Files Affected:

- (modified) 
clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp (+35-30) 
- (modified) 
clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.h (+1-20) 
- (modified) 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-trailing-return-type-cxx20.cpp
 (+1-1) 


``diff
diff --git 
a/clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp
index 9774e988d71e2..d90876d59a6ad 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp
@@ -113,7 +113,7 @@ struct UnqualNameVisitor : public 
RecursiveASTVisitor {
 };
 } // namespace
 
-constexpr llvm::StringLiteral Message =
+constexpr llvm::StringLiteral MessageFunction =
 "use a trailing return type for this function";
 
 static SourceLocation expandIfMacroId(SourceLocation Loc,
@@ -125,7 +125,7 @@ static SourceLocation expandIfMacroId(SourceLocation Loc,
   return Loc;
 }
 
-SourceLocation 
UseTrailingReturnTypeCheck::findTrailingReturnTypeSourceLocation(
+static SourceLocation findTrailingReturnTypeSourceLocation(
 const FunctionDecl &F, const FunctionTypeLoc &FTL, const ASTContext &Ctx,
 const SourceManager &SM, const LangOptions &LangOpts) {
   // We start with the location of the closing parenthesis.
@@ -217,10 +217,11 @@ classifyToken(const FunctionDecl &F, Preprocessor &PP, 
Token Tok) {
   return CT;
 }
 
-std::optional>
-UseTrailingReturnTypeCheck::classifyTokensBeforeFunctionName(
-const FunctionDecl &F, const ASTContext &Ctx, const SourceManager &SM,
-const LangOptions &LangOpts) {
+static std::optional>
+classifyTokensBeforeFunctionName(const FunctionDecl &F, const ASTContext &Ctx,
+ const SourceManager &SM,
+ const LangOptions &LangOpts,
+ Preprocessor *PP) {
   SourceLocation BeginF = expandIfMacroId(F.getBeginLoc(), SM);
   SourceLocation BeginNameF = expandIfMacroId(F.getLocation(), SM);
 
@@ -242,7 +243,6 @@ 
UseTrailingReturnTypeCheck::classifyTokensBeforeFunctionName(
 const MacroInfo *MI = PP->getMacroInfo(&Info);
 if (!MI || MI->isFunctionLike()) {
   // Cannot handle function style macros.
-  diag(F.getLocation(), Message);
   return std::nullopt;
 }
   }
@@ -253,10 +253,8 @@ 
UseTrailingReturnTypeCheck::classifyTokensBeforeFunctionName(
 
 if (std::optional CT = classifyToken(F, *PP, T))
   ClassifiedTokens.push_back(*CT);
-else {
-  diag(F.getLocation(), Message);
+else
   return std::nullopt;
-}
   }
 
   return ClassifiedTokens;
@@ -273,9 +271,10 @@ static bool hasAnyNestedLocalQualifiers(QualType Type) {
   return Result;
 }
 
-SourceRange UseTrailingReturnTypeCheck::findReturnTypeAndCVSourceRange(
-const FunctionDecl &F, const TypeLoc &ReturnLoc, const ASTContext &Ctx,
-const SourceManager &SM, const LangOptions &LangOpts) {
+static SourceRange
+findReturnTypeAndCVSourceRange(const FunctionDecl &F, const TypeLoc &ReturnLoc,
+   const ASTContext &Ctx, const SourceManager &SM,
+   const LangOptions &LangOpts, Preprocessor *PP) {
 
   // We start with the range of the return type and expand to neighboring
   // qualifiers (const, volatile and restrict).
@@ -283,7 +282,6 @@ SourceRange 
UseTrailingReturnTypeCheck::findReturnTypeAndCVSourceRange(
   if (ReturnTypeRange.isInvalid()) {
 // Happens if e.g. clang cannot resolve all includes and the return type is
 // unknown.
-diag(F.getLocation(), Message);
 return {};
   }
 
@@ -294,7 +292,7 @@ SourceRange 
UseTrailingReturnTypeCheck::findReturnTypeAndCVSourceRange(
 
   // Include qualifiers to the left and right of the return type.
   std::optional> MaybeTokens =
-  classifyTokensBeforeFunctionName(F, Ctx, SM, LangOpts);
+  classifyTokensBeforeFunctionName(F, Ctx, SM, LangOpts, PP);
   if (!MaybeTokens)
 return {};
   const SmallVector &Tokens = *MaybeTokens;
@@ -331,10 +329,11 @@ SourceRange 
UseTrailingReturnTypeCheck::findReturnTypeAndCVSourceRange(
   return ReturnTypeRange;
 }
 
-void UseTrailingReturnTypeCheck::keepSpecifiers(
-std::string &ReturnType, std::string &Auto, SourceRange ReturnTypeCVRange,
-const FunctionDecl &F, const FriendDecl *Fr, const ASTContext &Ctx,
-const SourceManager &SM, const LangOptions &LangOpts) {
+static void keepSpecifiers(std::string &ReturnType, std::string &Auto,

[clang-tools-extra] [clang-tidy][NFC] Refactor `modernize-use-trailing-return-type-check` check code and tests (PR #140759)

2025-05-20 Thread Baranov Victor via cfe-commits

https://github.com/vbvictor created 
https://github.com/llvm/llvm-project/pull/140759

- Deleted unused includes
- Deleted useless braces
- Converted private methods to static function to improve compilations speed 
and readability
- Modernized tests to use `cxx-or-later` 

>From fbae463925738d8628593d5daaabe2a299aecbbf Mon Sep 17 00:00:00 2001
From: Baranov Victor 
Date: Tue, 20 May 2025 19:23:35 +0300
Subject: [PATCH] [clang-tidy][nfc] refactor use-trailing-return-type-check
 private methods to be static functions and fix styling issues

---
 .../modernize/UseTrailingReturnTypeCheck.cpp  | 65 ++-
 .../modernize/UseTrailingReturnTypeCheck.h| 21 +-
 .../use-trailing-return-type-cxx20.cpp|  2 +-
 3 files changed, 37 insertions(+), 51 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp
index 9774e988d71e2..d90876d59a6ad 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseTrailingReturnTypeCheck.cpp
@@ -113,7 +113,7 @@ struct UnqualNameVisitor : public 
RecursiveASTVisitor {
 };
 } // namespace
 
-constexpr llvm::StringLiteral Message =
+constexpr llvm::StringLiteral MessageFunction =
 "use a trailing return type for this function";
 
 static SourceLocation expandIfMacroId(SourceLocation Loc,
@@ -125,7 +125,7 @@ static SourceLocation expandIfMacroId(SourceLocation Loc,
   return Loc;
 }
 
-SourceLocation 
UseTrailingReturnTypeCheck::findTrailingReturnTypeSourceLocation(
+static SourceLocation findTrailingReturnTypeSourceLocation(
 const FunctionDecl &F, const FunctionTypeLoc &FTL, const ASTContext &Ctx,
 const SourceManager &SM, const LangOptions &LangOpts) {
   // We start with the location of the closing parenthesis.
@@ -217,10 +217,11 @@ classifyToken(const FunctionDecl &F, Preprocessor &PP, 
Token Tok) {
   return CT;
 }
 
-std::optional>
-UseTrailingReturnTypeCheck::classifyTokensBeforeFunctionName(
-const FunctionDecl &F, const ASTContext &Ctx, const SourceManager &SM,
-const LangOptions &LangOpts) {
+static std::optional>
+classifyTokensBeforeFunctionName(const FunctionDecl &F, const ASTContext &Ctx,
+ const SourceManager &SM,
+ const LangOptions &LangOpts,
+ Preprocessor *PP) {
   SourceLocation BeginF = expandIfMacroId(F.getBeginLoc(), SM);
   SourceLocation BeginNameF = expandIfMacroId(F.getLocation(), SM);
 
@@ -242,7 +243,6 @@ 
UseTrailingReturnTypeCheck::classifyTokensBeforeFunctionName(
 const MacroInfo *MI = PP->getMacroInfo(&Info);
 if (!MI || MI->isFunctionLike()) {
   // Cannot handle function style macros.
-  diag(F.getLocation(), Message);
   return std::nullopt;
 }
   }
@@ -253,10 +253,8 @@ 
UseTrailingReturnTypeCheck::classifyTokensBeforeFunctionName(
 
 if (std::optional CT = classifyToken(F, *PP, T))
   ClassifiedTokens.push_back(*CT);
-else {
-  diag(F.getLocation(), Message);
+else
   return std::nullopt;
-}
   }
 
   return ClassifiedTokens;
@@ -273,9 +271,10 @@ static bool hasAnyNestedLocalQualifiers(QualType Type) {
   return Result;
 }
 
-SourceRange UseTrailingReturnTypeCheck::findReturnTypeAndCVSourceRange(
-const FunctionDecl &F, const TypeLoc &ReturnLoc, const ASTContext &Ctx,
-const SourceManager &SM, const LangOptions &LangOpts) {
+static SourceRange
+findReturnTypeAndCVSourceRange(const FunctionDecl &F, const TypeLoc &ReturnLoc,
+   const ASTContext &Ctx, const SourceManager &SM,
+   const LangOptions &LangOpts, Preprocessor *PP) {
 
   // We start with the range of the return type and expand to neighboring
   // qualifiers (const, volatile and restrict).
@@ -283,7 +282,6 @@ SourceRange 
UseTrailingReturnTypeCheck::findReturnTypeAndCVSourceRange(
   if (ReturnTypeRange.isInvalid()) {
 // Happens if e.g. clang cannot resolve all includes and the return type is
 // unknown.
-diag(F.getLocation(), Message);
 return {};
   }
 
@@ -294,7 +292,7 @@ SourceRange 
UseTrailingReturnTypeCheck::findReturnTypeAndCVSourceRange(
 
   // Include qualifiers to the left and right of the return type.
   std::optional> MaybeTokens =
-  classifyTokensBeforeFunctionName(F, Ctx, SM, LangOpts);
+  classifyTokensBeforeFunctionName(F, Ctx, SM, LangOpts, PP);
   if (!MaybeTokens)
 return {};
   const SmallVector &Tokens = *MaybeTokens;
@@ -331,10 +329,11 @@ SourceRange 
UseTrailingReturnTypeCheck::findReturnTypeAndCVSourceRange(
   return ReturnTypeRange;
 }
 
-void UseTrailingReturnTypeCheck::keepSpecifiers(
-std::string &ReturnType, std::string &Auto, SourceRange ReturnTypeCVRange,
-const FunctionDecl &F, const FriendDecl *Fr, const ASTContext &Ctx,
-const SourceManager &SM, c