================
@@ -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
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to