[clang-tools-extra] [clang] [clang-tidy] Added new check to detect redundant inline keyword (PR #73069)

via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 23 15:48:42 PST 2023


=?utf-8?q?Félix-Antoine?= Constantin,
=?utf-8?q?Félix-Antoine?= Constantin
Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/73069 at github.com>


github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. :warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff 42d484082cd190400e0e493a8d679762ce0efbba 3fadac1a7cab42eb962eaa4b6f79335e77196c4d -- clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.h clang-tools-extra/test/clang-tidy/checkers/readability/redundant-inline-specifier.cpp clang-tools-extra/clang-tidy/readability/ReadabilityTidyModule.cpp
``````````

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp b/clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp
index 65fd363ebf..4a685c83c2 100644
--- a/clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp
@@ -24,9 +24,9 @@ using namespace clang::ast_matchers;
 
 namespace clang::tidy::readability {
 
-AST_POLYMORPHIC_MATCHER(isInlineSpecified, AST_POLYMORPHIC_SUPPORTED_TYPES(
-                                                      FunctionDecl,
-                                                                  VarDecl)) {
+AST_POLYMORPHIC_MATCHER(isInlineSpecified,
+                        AST_POLYMORPHIC_SUPPORTED_TYPES(FunctionDecl,
+                                                        VarDecl)) {
   if (const auto *FD = dyn_cast<FunctionDecl>(&Node))
     return FD->isInlineSpecified();
   if (const auto *VD = dyn_cast<VarDecl>(&Node))
@@ -34,13 +34,12 @@ AST_POLYMORPHIC_MATCHER(isInlineSpecified, AST_POLYMORPHIC_SUPPORTED_TYPES(
   llvm_unreachable("Not a valid polymorphic type");
 }
 
-
 static std::optional<SourceLocation>
 getInlineTokenLocation(SourceRange RangeLocation, const SourceManager &Sources,
                        const LangOptions &LangOpts) {
   Token FirstToken;
   Lexer::getRawToken(RangeLocation.getBegin(), FirstToken, Sources, LangOpts,
-                             true);
+                     true);
   std::optional<Token> CurrentToken = FirstToken;
   while (CurrentToken && CurrentToken->getLocation() < RangeLocation.getEnd() &&
          CurrentToken->isNot(tok::eof)) {
@@ -48,7 +47,8 @@ getInlineTokenLocation(SourceRange RangeLocation, const SourceManager &Sources,
         CurrentToken->getRawIdentifier() == "inline")
       return CurrentToken->getLocation();
 
-    CurrentToken = Lexer::findNextToken(CurrentToken->getLocation(), Sources, LangOpts);
+    CurrentToken =
+        Lexer::findNextToken(CurrentToken->getLocation(), Sources, LangOpts);
   }
   return std::nullopt;
 }
@@ -71,7 +71,8 @@ void RedundantInlineSpecifierCheck::registerMatchers(MatchFinder *Finder) {
       this);
 
   Finder->addMatcher(
-      functionTemplateDecl(has(functionDecl(isInlineSpecified()))).bind("templ_decl"),
+      functionTemplateDecl(has(functionDecl(isInlineSpecified())))
+          .bind("templ_decl"),
       this);
 }
 
@@ -79,8 +80,9 @@ template <typename T>
 void RedundantInlineSpecifierCheck::handleMatchedDecl(
     const T *MatchedDecl, const SourceManager &Sources,
     const MatchFinder::MatchResult &Result, StringRef Message) {
-  if (std::optional<SourceLocation> Loc = getInlineTokenLocation(MatchedDecl->getSourceRange(), Sources,
-                                        Result.Context->getLangOpts()))
+  if (std::optional<SourceLocation> Loc =
+          getInlineTokenLocation(MatchedDecl->getSourceRange(), Sources,
+                                 Result.Context->getLangOpts()))
     diag(*Loc, Message) << MatchedDecl << FixItHint::CreateRemoval(*Loc);
 }
 
diff --git a/clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.h b/clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.h
index 1a510f586f..b4d1f2159a 100644
--- a/clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.h
+++ b/clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.h
@@ -13,7 +13,8 @@
 
 namespace clang::tidy::readability {
 
-/// Detects redundant ``inline`` specifiers on function and variable declarations.
+/// Detects redundant ``inline`` specifiers on function and variable
+/// declarations.
 ///
 /// For the user-facing documentation see:
 /// http://clang.llvm.org/extra/clang-tidy/checks/readability/readability-redundant-inline-specifier.html

``````````

</details>


https://github.com/llvm/llvm-project/pull/73069


More information about the cfe-commits mailing list