[clang] [Clang] Fix template elision to preserve qualifiers in diagnostics (PR #180175)

Corentin Jabot via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 6 05:58:02 PST 2026


================
@@ -1205,8 +1205,15 @@ class TemplateDiff {
              "Both template specializations need to be valid.");
       Qualifiers FromQual = FromType.getQualifiers(),
                  ToQual = ToType.getQualifiers();
-      FromQual -= QualType(FromArgTST, 0).getQualifiers();
-      ToQual -= QualType(ToArgTST, 0).getQualifiers();
+      // FromQual -= QualType(FromArgTST, 0).getQualifiers();
+      // ToQual -= QualType(ToArgTST, 0).getQualifiers();
+      bool Same = false;
+      if (FromArgTST->getTemplateName().getAsTemplateDecl() == 
+          ToArgTST->getTemplateName().getAsTemplateDecl()) {
+        // If the names match, the ONLY thing that makes them different is the Qualifiers
----------------
cor3ntin wrote:

```suggestion
        // If the template are the same, the types might still differ by their qualification.
```

You could rewrite the whole thing as


```cpp
bool Same = FromArgTST->getTemplateName().getAsTemplateDecl() == 
          ToArgTST->getTemplateName().getAsTemplateDecl() && FromQual == ToQual;
```

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


More information about the cfe-commits mailing list