[clang] [clang] AST Visitor: skip empty qualifiers in QualifiedTemplateName (PR #93926)

Matheus Izvekov via cfe-commits cfe-commits at lists.llvm.org
Thu May 30 23:58:50 PDT 2024


================
@@ -855,10 +855,14 @@ bool RecursiveASTVisitor<Derived>::TraverseDeclarationNameInfo(
 
 template <typename Derived>
 bool RecursiveASTVisitor<Derived>::TraverseTemplateName(TemplateName Template) {
-  if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
+  if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
     TRY_TO(TraverseNestedNameSpecifier(DTN->getQualifier()));
-  else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
-    TRY_TO(TraverseNestedNameSpecifier(QTN->getQualifier()));
+  } else if (QualifiedTemplateName *QTN =
+                 Template.getAsQualifiedTemplateName()) {
+    if (QTN->getQualifier()) {
+      TRY_TO(TraverseNestedNameSpecifier(QTN->getQualifier()));
+    }
+  }
----------------
mizvekov wrote:

I understand that looks cleaner at first glance, but the intention in the original code was to match each kind of `TemplateName`.

For example, this doesn't traverse `OverloadTemplateName` right now, but if we wanted to add it after this change, this would necessitate to refactor the if branches once again.

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


More information about the cfe-commits mailing list