[clang-tools-extra] [clang-tidy] added `IgnoreAliasing` option to `readability-qualified-auto check` (PR #147060)

Baranov Victor via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 15 11:20:02 PDT 2025


================
@@ -134,14 +136,26 @@ void QualifiedAutoCheck::registerMatchers(MatchFinder *Finder) {
 
   auto IsBoundToType = refersToType(equalsBoundNode("type"));
   auto UnlessFunctionType = unless(hasUnqualifiedDesugaredType(functionType()));
-  auto IsAutoDeducedToPointer = [](const std::vector<StringRef> &AllowedTypes,
-                                   const auto &...InnerMatchers) {
-    return autoType(hasDeducedType(
-        hasUnqualifiedDesugaredType(pointerType(pointee(InnerMatchers...))),
-        unless(hasUnqualifiedType(
-            matchers::matchesAnyListedTypeName(AllowedTypes, false))),
-        unless(pointerType(pointee(hasUnqualifiedType(
-            matchers::matchesAnyListedTypeName(AllowedTypes, false)))))));
+  auto IsAutoDeducedToPointer = [this](
+                                    const std::vector<StringRef> &AllowedTypes,
+                                    const auto &...InnerMatchers) {
+    if (this->IgnoreAliasing) {
+      return autoType(hasDeducedType(
+          hasUnqualifiedDesugaredType(pointerType(pointee(InnerMatchers...))),
+          unless(hasUnqualifiedType(
+              matchers::matchesAnyListedTypeName(AllowedTypes, false))),
+          unless(pointerType(pointee(hasUnqualifiedType(
+              matchers::matchesAnyListedTypeName(AllowedTypes, false)))))));
+    } else {
+      return autoType(hasDeducedType(
+          anyOf(qualType(pointerType(pointee(InnerMatchers...))),
+                qualType(substTemplateTypeParmType(hasReplacementType(
+                    pointerType(pointee(InnerMatchers...)))))),
+          unless(hasUnqualifiedType(
+              matchers::matchesAnyListedTypeName(AllowedTypes, false))),
+          unless(pointerType(pointee(hasUnqualifiedType(
+              matchers::matchesAnyListedTypeName(AllowedTypes, false)))))));
+    }
----------------
vbvictor wrote:

Could you please try make a single matcher instead of 2 matchers inside `if`.
This part is repeated in both branches:
```cpp
unless(hasUnqualifiedType(
    matchers::matchesAnyListedTypeName(AllowedTypes, false))),
unless(pointerType(pointee(hasUnqualifiedType(
    matchers::matchesAnyListedTypeName(AllowedTypes, false))))))
```
I suppose you could write like:
```cpp
autoType(hasDeducedType(
          this->IgnoreAliasing ?
              hasUnqualifiedDesugaredType(pointerType(pointee(InnerMatchers...)))
          :
              anyOf(qualType(pointerType(pointee(InnerMatchers...))),
                    qualType(substTemplateTypeParmType(hasReplacementType(
                        pointerType(pointee(InnerMatchers...)))))),
          unless(hasUnqualifiedType(
              matchers::matchesAnyListedTypeName(AllowedTypes, false))),
          unless(pointerType(pointee(hasUnqualifiedType(
              matchers::matchesAnyListedTypeName(AllowedTypes, false)))))))
```
Or if this is not possible, then put common part with `AllowedTypes` into a submatcher to avoid copypaste.

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


More information about the cfe-commits mailing list