Skip to content

[clang-tidy][NFC] move AST_MATCHER to anonymous namespace in InfiniteLoopCheck #118820

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 5, 2024

Conversation

HerrCai0907
Copy link
Contributor

No description provided.

@llvmbot
Copy link
Member

llvmbot commented Dec 5, 2024

@llvm/pr-subscribers-clang-tidy

Author: Congcong Cai (HerrCai0907)

Changes

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

1 Files Affected:

  • (modified) clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp (+12-12)
diff --git a/clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
index 2b2d80ea9346bd..b7f0c08b2a7d4b 100644
--- a/clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
@@ -13,13 +13,15 @@
 #include "clang/Analysis/Analyses/ExprMutationAnalyzer.h"
 #include "clang/Analysis/CallGraph.h"
 #include "llvm/ADT/SCCIterator.h"
-#include "llvm/ADT/SmallVector.h"
 
 using namespace clang::ast_matchers;
+using clang::ast_matchers::internal::Matcher;
 using clang::tidy::utils::hasPtrOrReferenceInFunc;
 
 namespace clang {
-namespace ast_matchers {
+namespace tidy::bugprone {
+
+namespace {
 /// matches a Decl if it has a  "no return" attribute of any kind
 AST_MATCHER(Decl, declHasNoReturnAttr) {
   return Node.hasAttr<NoReturnAttr>() || Node.hasAttr<CXX11NoReturnAttr>() ||
@@ -30,23 +32,21 @@ AST_MATCHER(Decl, declHasNoReturnAttr) {
 AST_MATCHER(FunctionType, typeHasNoReturnAttr) {
   return Node.getNoReturnAttr();
 }
-} // namespace ast_matchers
-namespace tidy::bugprone {
+} // namespace
 
-static internal::Matcher<Stmt>
-loopEndingStmt(internal::Matcher<Stmt> Internal) {
-  internal::Matcher<QualType> isNoReturnFunType =
+static Matcher<Stmt> loopEndingStmt(Matcher<Stmt> Internal) {
+  Matcher<QualType> IsNoReturnFunType =
       ignoringParens(functionType(typeHasNoReturnAttr()));
-  internal::Matcher<Decl> isNoReturnDecl =
-      anyOf(declHasNoReturnAttr(), functionDecl(hasType(isNoReturnFunType)),
-            varDecl(hasType(blockPointerType(pointee(isNoReturnFunType)))));
+  Matcher<Decl> IsNoReturnDecl =
+      anyOf(declHasNoReturnAttr(), functionDecl(hasType(IsNoReturnFunType)),
+            varDecl(hasType(blockPointerType(pointee(IsNoReturnFunType)))));
 
   return stmt(anyOf(
       mapAnyOf(breakStmt, returnStmt, gotoStmt, cxxThrowExpr).with(Internal),
       callExpr(Internal,
                callee(mapAnyOf(functionDecl, /* block callee */ varDecl)
-                          .with(isNoReturnDecl))),
-      objcMessageExpr(Internal, callee(isNoReturnDecl))));
+                          .with(IsNoReturnDecl))),
+      objcMessageExpr(Internal, callee(IsNoReturnDecl))));
 }
 
 /// Return whether `Var` was changed in `LoopStmt`.

@llvmbot
Copy link
Member

llvmbot commented Dec 5, 2024

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

Author: Congcong Cai (HerrCai0907)

Changes

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

1 Files Affected:

  • (modified) clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp (+12-12)
diff --git a/clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
index 2b2d80ea9346bd..b7f0c08b2a7d4b 100644
--- a/clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
@@ -13,13 +13,15 @@
 #include "clang/Analysis/Analyses/ExprMutationAnalyzer.h"
 #include "clang/Analysis/CallGraph.h"
 #include "llvm/ADT/SCCIterator.h"
-#include "llvm/ADT/SmallVector.h"
 
 using namespace clang::ast_matchers;
+using clang::ast_matchers::internal::Matcher;
 using clang::tidy::utils::hasPtrOrReferenceInFunc;
 
 namespace clang {
-namespace ast_matchers {
+namespace tidy::bugprone {
+
+namespace {
 /// matches a Decl if it has a  "no return" attribute of any kind
 AST_MATCHER(Decl, declHasNoReturnAttr) {
   return Node.hasAttr<NoReturnAttr>() || Node.hasAttr<CXX11NoReturnAttr>() ||
@@ -30,23 +32,21 @@ AST_MATCHER(Decl, declHasNoReturnAttr) {
 AST_MATCHER(FunctionType, typeHasNoReturnAttr) {
   return Node.getNoReturnAttr();
 }
-} // namespace ast_matchers
-namespace tidy::bugprone {
+} // namespace
 
-static internal::Matcher<Stmt>
-loopEndingStmt(internal::Matcher<Stmt> Internal) {
-  internal::Matcher<QualType> isNoReturnFunType =
+static Matcher<Stmt> loopEndingStmt(Matcher<Stmt> Internal) {
+  Matcher<QualType> IsNoReturnFunType =
       ignoringParens(functionType(typeHasNoReturnAttr()));
-  internal::Matcher<Decl> isNoReturnDecl =
-      anyOf(declHasNoReturnAttr(), functionDecl(hasType(isNoReturnFunType)),
-            varDecl(hasType(blockPointerType(pointee(isNoReturnFunType)))));
+  Matcher<Decl> IsNoReturnDecl =
+      anyOf(declHasNoReturnAttr(), functionDecl(hasType(IsNoReturnFunType)),
+            varDecl(hasType(blockPointerType(pointee(IsNoReturnFunType)))));
 
   return stmt(anyOf(
       mapAnyOf(breakStmt, returnStmt, gotoStmt, cxxThrowExpr).with(Internal),
       callExpr(Internal,
                callee(mapAnyOf(functionDecl, /* block callee */ varDecl)
-                          .with(isNoReturnDecl))),
-      objcMessageExpr(Internal, callee(isNoReturnDecl))));
+                          .with(IsNoReturnDecl))),
+      objcMessageExpr(Internal, callee(IsNoReturnDecl))));
 }
 
 /// Return whether `Var` was changed in `LoopStmt`.

@HerrCai0907 HerrCai0907 changed the title [clang-tidy][NFC] move AST_MATCHER to namespace in InfiniteLoopCheck [clang-tidy][NFC] move AST_MATCHER to anonymous namespace in InfiniteLoopCheck Dec 5, 2024
Copy link
Contributor

@5chmidti 5chmidti left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@HerrCai0907 HerrCai0907 merged commit 63dfe70 into llvm:main Dec 5, 2024
11 checks passed
@HerrCai0907 HerrCai0907 deleted the fix/InfiniteLoopCheck-format branch December 13, 2024 02:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants