Skip to content

Conversation

vbvictor
Copy link
Contributor

"QualifierAlignment: Left" is an established way of writing code in clang-tools-extra/clang-tidy. We should enforce it in CI.

This patch fixes all findings in current files that doesn't align with left-alignment style.

@llvmbot
Copy link
Member

llvmbot commented Aug 28, 2025

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

@llvm/pr-subscribers-clang-tidy

Author: Baranov Victor (vbvictor)

Changes

"QualifierAlignment: Left" is an established way of writing code in clang-tools-extra/clang-tidy. We should enforce it in CI.

This patch fixes all findings in current files that doesn't align with left-alignment style.


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

10 Files Affected:

  • (added) clang-tools-extra/clang-tidy/.clang-format (+2)
  • (modified) clang-tools-extra/clang-tidy/bugprone/CapturingThisInMemberVariableCheck.cpp (+2-2)
  • (modified) clang-tools-extra/clang-tidy/bugprone/MultiLevelImplicitPointerConversionCheck.h (+1-1)
  • (modified) clang-tools-extra/clang-tidy/bugprone/SmartPtrArrayMismatchCheck.h (+1-1)
  • (modified) clang-tools-extra/clang-tidy/bugprone/UnusedLocalNonTrivialVariableCheck.cpp (+1-1)
  • (modified) clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidConstOrRefDataMembersCheck.cpp (+16-16)
  • (modified) clang-tools-extra/clang-tidy/misc/OverrideWithDifferentVisibilityCheck.cpp (+2-2)
  • (modified) clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp (+2-2)
  • (modified) clang-tools-extra/clang-tidy/modernize/UseAutoCheck.cpp (+2-2)
  • (modified) clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp (+7-7)
diff --git a/clang-tools-extra/clang-tidy/.clang-format b/clang-tools-extra/clang-tidy/.clang-format
new file mode 100644
index 0000000000000..d18cf7c108ca6
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/.clang-format
@@ -0,0 +1,2 @@
+BasedOnStyle: LLVM
+QualifierAlignment: Left
diff --git a/clang-tools-extra/clang-tidy/bugprone/CapturingThisInMemberVariableCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/CapturingThisInMemberVariableCheck.cpp
index 1bfe384258ddb..f188ae5ec81b1 100644
--- a/clang-tools-extra/clang-tidy/bugprone/CapturingThisInMemberVariableCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/CapturingThisInMemberVariableCheck.cpp
@@ -44,11 +44,11 @@ AST_MATCHER(CXXRecordDecl, correctHandleCaptureThisLambda) {
   if (Node.hasSimpleMoveAssignment())
     return false;
 
-  for (CXXConstructorDecl const *C : Node.ctors()) {
+  for (const CXXConstructorDecl *C : Node.ctors()) {
     if (C->isCopyOrMoveConstructor() && C->isDefaulted() && !C->isDeleted())
       return false;
   }
-  for (CXXMethodDecl const *M : Node.methods()) {
+  for (const CXXMethodDecl *M : Node.methods()) {
     if (M->isCopyAssignmentOperator())
       llvm::errs() << M->isDeleted() << "\n";
     if (M->isCopyAssignmentOperator() && M->isDefaulted() && !M->isDeleted())
diff --git a/clang-tools-extra/clang-tidy/bugprone/MultiLevelImplicitPointerConversionCheck.h b/clang-tools-extra/clang-tidy/bugprone/MultiLevelImplicitPointerConversionCheck.h
index ef5f9f103c893..5ec78be0ea79b 100644
--- a/clang-tools-extra/clang-tidy/bugprone/MultiLevelImplicitPointerConversionCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/MultiLevelImplicitPointerConversionCheck.h
@@ -31,7 +31,7 @@ class MultiLevelImplicitPointerConversionCheck : public ClangTidyCheck {
   }
 
 private:
-  bool const EnableInC;
+  const bool EnableInC;
 };
 
 } // namespace clang::tidy::bugprone
diff --git a/clang-tools-extra/clang-tidy/bugprone/SmartPtrArrayMismatchCheck.h b/clang-tools-extra/clang-tidy/bugprone/SmartPtrArrayMismatchCheck.h
index e9f1a6ac5a6a2..7fcc4b6cfa0e6 100644
--- a/clang-tools-extra/clang-tidy/bugprone/SmartPtrArrayMismatchCheck.h
+++ b/clang-tools-extra/clang-tidy/bugprone/SmartPtrArrayMismatchCheck.h
@@ -40,7 +40,7 @@ class SmartPtrArrayMismatchCheck : public ClangTidyCheck {
   static const char PointerTypeN[];
 
 private:
-  StringRef const SmartPointerName;
+  const StringRef SmartPointerName;
 };
 
 } // namespace clang::tidy::bugprone
diff --git a/clang-tools-extra/clang-tidy/bugprone/UnusedLocalNonTrivialVariableCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/UnusedLocalNonTrivialVariableCheck.cpp
index ac494152fdfdb..3b6969a57c2b8 100644
--- a/clang-tools-extra/clang-tidy/bugprone/UnusedLocalNonTrivialVariableCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/UnusedLocalNonTrivialVariableCheck.cpp
@@ -33,7 +33,7 @@ AST_MATCHER(VarDecl, isReferenced) { return Node.isReferenced(); }
 AST_MATCHER(VarDecl, explicitMarkUnused) {
   // Implementations should not emit a warning that a name-independent
   // declaration is used or unused.
-  LangOptions const &LangOpts = Finder->getASTContext().getLangOpts();
+  const LangOptions &LangOpts = Finder->getASTContext().getLangOpts();
   return Node.hasAttr<UnusedAttr>() ||
          (LangOpts.CPlusPlus26 && Node.isPlaceholderVar(LangOpts));
 }
diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidConstOrRefDataMembersCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidConstOrRefDataMembersCheck.cpp
index f615976c7edb6..dd913c92d60a0 100644
--- a/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidConstOrRefDataMembersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/AvoidConstOrRefDataMembersCheck.cpp
@@ -14,73 +14,73 @@ using namespace clang::ast_matchers;
 
 namespace clang::tidy::cppcoreguidelines {
 
-static bool isCopyConstructible(CXXRecordDecl const &Node) {
+static bool isCopyConstructible(const CXXRecordDecl &Node) {
   if (Node.needsOverloadResolutionForCopyConstructor() &&
       Node.needsImplicitCopyConstructor()) {
     // unresolved
-    for (CXXBaseSpecifier const &BS : Node.bases()) {
-      CXXRecordDecl const *BRD = BS.getType()->getAsCXXRecordDecl();
+    for (const CXXBaseSpecifier &BS : Node.bases()) {
+      const CXXRecordDecl *BRD = BS.getType()->getAsCXXRecordDecl();
       if (BRD != nullptr && !isCopyConstructible(*BRD))
         return false;
     }
   }
   if (Node.hasSimpleCopyConstructor())
     return true;
-  for (CXXConstructorDecl const *Ctor : Node.ctors())
+  for (const CXXConstructorDecl *Ctor : Node.ctors())
     if (Ctor->isCopyConstructor())
       return !Ctor->isDeleted();
   return false;
 }
 
-static bool isMoveConstructible(CXXRecordDecl const &Node) {
+static bool isMoveConstructible(const CXXRecordDecl &Node) {
   if (Node.needsOverloadResolutionForMoveConstructor() &&
       Node.needsImplicitMoveConstructor()) {
     // unresolved
-    for (CXXBaseSpecifier const &BS : Node.bases()) {
-      CXXRecordDecl const *BRD = BS.getType()->getAsCXXRecordDecl();
+    for (const CXXBaseSpecifier &BS : Node.bases()) {
+      const CXXRecordDecl *BRD = BS.getType()->getAsCXXRecordDecl();
       if (BRD != nullptr && !isMoveConstructible(*BRD))
         return false;
     }
   }
   if (Node.hasSimpleMoveConstructor())
     return true;
-  for (CXXConstructorDecl const *Ctor : Node.ctors())
+  for (const CXXConstructorDecl *Ctor : Node.ctors())
     if (Ctor->isMoveConstructor())
       return !Ctor->isDeleted();
   return false;
 }
 
-static bool isCopyAssignable(CXXRecordDecl const &Node) {
+static bool isCopyAssignable(const CXXRecordDecl &Node) {
   if (Node.needsOverloadResolutionForCopyAssignment() &&
       Node.needsImplicitCopyAssignment()) {
     // unresolved
-    for (CXXBaseSpecifier const &BS : Node.bases()) {
-      CXXRecordDecl const *BRD = BS.getType()->getAsCXXRecordDecl();
+    for (const CXXBaseSpecifier &BS : Node.bases()) {
+      const CXXRecordDecl *BRD = BS.getType()->getAsCXXRecordDecl();
       if (BRD != nullptr && !isCopyAssignable(*BRD))
         return false;
     }
   }
   if (Node.hasSimpleCopyAssignment())
     return true;
-  for (CXXMethodDecl const *Method : Node.methods())
+  for (const CXXMethodDecl *Method : Node.methods())
     if (Method->isCopyAssignmentOperator())
       return !Method->isDeleted();
   return false;
 }
 
-static bool isMoveAssignable(CXXRecordDecl const &Node) {
+static bool isMoveAssignable(const CXXRecordDecl &Node) {
   if (Node.needsOverloadResolutionForMoveAssignment() &&
       Node.needsImplicitMoveAssignment()) {
     // unresolved
-    for (CXXBaseSpecifier const &BS : Node.bases()) {
-      CXXRecordDecl const *BRD = BS.getType()->getAsCXXRecordDecl();
+    for (const CXXBaseSpecifier &BS : Node.bases()) {
+      const CXXRecordDecl *BRD = BS.getType()->getAsCXXRecordDecl();
       if (BRD != nullptr && !isMoveAssignable(*BRD))
         return false;
     }
   }
   if (Node.hasSimpleMoveAssignment())
     return true;
-  for (CXXMethodDecl const *Method : Node.methods())
+  for (const CXXMethodDecl *Method : Node.methods())
     if (Method->isMoveAssignmentOperator())
       return !Method->isDeleted();
   return false;
diff --git a/clang-tools-extra/clang-tidy/misc/OverrideWithDifferentVisibilityCheck.cpp b/clang-tools-extra/clang-tidy/misc/OverrideWithDifferentVisibilityCheck.cpp
index 12f78affe463e..2fe0bcf67a3d7 100644
--- a/clang-tools-extra/clang-tidy/misc/OverrideWithDifferentVisibilityCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/OverrideWithDifferentVisibilityCheck.cpp
@@ -17,7 +17,7 @@ using namespace clang;
 namespace {
 
 AST_MATCHER(NamedDecl, isOperatorDecl) {
-  DeclarationName::NameKind const NK = Node.getDeclName().getNameKind();
+  const DeclarationName::NameKind NK = Node.getDeclName().getNameKind();
   return NK != DeclarationName::Identifier &&
          NK != DeclarationName::CXXConstructorName &&
          NK != DeclarationName::CXXDestructorName;
@@ -104,7 +104,7 @@ void OverrideWithDifferentVisibilityCheck::check(
 
   const auto *const OverriddenFunction =
       Result.Nodes.getNodeAs<FunctionDecl>("base_func");
-  AccessSpecifier const ActualAccess = MatchedFunction->getAccess();
+  const AccessSpecifier ActualAccess = MatchedFunction->getAccess();
   AccessSpecifier OverriddenAccess = OverriddenFunction->getAccess();
 
   const CXXBaseSpecifier *InheritanceWithStrictVisibility = nullptr;
diff --git a/clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp b/clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
index f6404dbfce232..5d11843fea65c 100644
--- a/clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
@@ -152,14 +152,14 @@ void ConcatNestedNamespacesCheck::reportDiagnostic(
       ConcatNameSpace.append("::");
   }
 
-  for (SourceRange const &Front : Fronts)
+  for (const SourceRange &Front : Fronts)
     DB << FixItHint::CreateRemoval(Front);
   DB << FixItHint::CreateReplacement(
       Namespaces.back().getReplacedNamespaceFrontRange(), ConcatNameSpace);
   if (LastRBrace != Namespaces.back().getDefaultNamespaceBackRange())
     DB << FixItHint::CreateReplacement(LastRBrace,
                                        ("} // " + ConcatNameSpace).str());
-  for (SourceRange const &Back : llvm::reverse(Backs))
+  for (const SourceRange &Back : llvm::reverse(Backs))
     DB << FixItHint::CreateRemoval(Back);
 }
 
diff --git a/clang-tools-extra/clang-tidy/modernize/UseAutoCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseAutoCheck.cpp
index b601620633cee..aedfda83838cd 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseAutoCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseAutoCheck.cpp
@@ -334,14 +334,14 @@ void UseAutoCheck::replaceIterators(const DeclStmt *D, ASTContext *Context) {
 
 static void ignoreTypeLocClasses(
     TypeLoc &Loc,
-    std::initializer_list<TypeLoc::TypeLocClass> const &LocClasses) {
+    const std::initializer_list<TypeLoc::TypeLocClass> &LocClasses) {
   while (llvm::is_contained(LocClasses, Loc.getTypeLocClass()))
     Loc = Loc.getNextTypeLoc();
 }
 
 static bool isMultiLevelPointerToTypeLocClasses(
     TypeLoc Loc,
-    std::initializer_list<TypeLoc::TypeLocClass> const &LocClasses) {
+    const std::initializer_list<TypeLoc::TypeLocClass> &LocClasses) {
   ignoreTypeLocClasses(Loc, {TypeLoc::Paren, TypeLoc::Qualified});
   TypeLoc::TypeLocClass TLC = Loc.getTypeLocClass();
   if (TLC != TypeLoc::Pointer && TLC != TypeLoc::MemberPointer)
diff --git a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
index fab2365f1147a..3df4a031fac8f 100644
--- a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -953,7 +953,7 @@ std::string IdentifierNamingCheck::fixupWithCase(
     break;
 
   case IdentifierNamingCheck::CT_LowerCase:
-    for (auto const &Word : Words) {
+    for (const auto &Word : Words) {
       if (&Word != &Words.front())
         Fixup += "_";
       Fixup += Word.lower();
@@ -961,7 +961,7 @@ std::string IdentifierNamingCheck::fixupWithCase(
     break;
 
   case IdentifierNamingCheck::CT_UpperCase:
-    for (auto const &Word : Words) {
+    for (const auto &Word : Words) {
       if (&Word != &Words.front())
         Fixup += "_";
       Fixup += Word.upper();
@@ -969,14 +969,14 @@ std::string IdentifierNamingCheck::fixupWithCase(
     break;
 
   case IdentifierNamingCheck::CT_CamelCase:
-    for (auto const &Word : Words) {
+    for (const auto &Word : Words) {
       Fixup += toupper(Word.front());
       Fixup += Word.substr(1).lower();
     }
     break;
 
   case IdentifierNamingCheck::CT_CamelBack:
-    for (auto const &Word : Words) {
+    for (const auto &Word : Words) {
       if (&Word == &Words.front()) {
         Fixup += Word.lower();
       } else {
@@ -987,7 +987,7 @@ std::string IdentifierNamingCheck::fixupWithCase(
     break;
 
   case IdentifierNamingCheck::CT_CamelSnakeCase:
-    for (auto const &Word : Words) {
+    for (const auto &Word : Words) {
       if (&Word != &Words.front())
         Fixup += "_";
       Fixup += toupper(Word.front());
@@ -996,7 +996,7 @@ std::string IdentifierNamingCheck::fixupWithCase(
     break;
 
   case IdentifierNamingCheck::CT_CamelSnakeBack:
-    for (auto const &Word : Words) {
+    for (const auto &Word : Words) {
       if (&Word != &Words.front()) {
         Fixup += "_";
         Fixup += toupper(Word.front());
@@ -1008,7 +1008,7 @@ std::string IdentifierNamingCheck::fixupWithCase(
     break;
 
   case IdentifierNamingCheck::CT_LeadingUpperSnakeCase:
-    for (auto const &Word : Words) {
+    for (const auto &Word : Words) {
       if (&Word != &Words.front()) {
         Fixup += "_";
         Fixup += Word.lower();

Copy link
Contributor

@carlosgalvezp carlosgalvezp left a comment

Choose a reason for hiding this comment

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

LGTM! Worth keeping in mind that this new .clang-format file makes clang-tidy potentially disconnected from the rest of the repo, in case the top-level file were to introduce new options. But hopefully everything is baked into the "LLVM" style.

@vbvictor
Copy link
Contributor Author

vbvictor commented Aug 28, 2025

LGTM! Worth keeping in mind that this new .clang-format file makes clang-tidy potentially disconnected from the rest of the repo, in case the top-level file were to introduce new options. But hopefully everything is baked into the "LLVM" style.

Some other projects (mlir, libcxx) use custom configs so we will be in the same boat if anything happens:).

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