[clang] [Clang] Fix template elision to preserve qualifiers in diagnostics (PR #180175)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Feb 6 03:56:23 PST 2026
https://github.com/Lambo-IITian created https://github.com/llvm/llvm-project/pull/180175
### Description
Fixes #180046
This PR addresses issue #180046 where Clang elides the wrong part of template types in error messages, specifically hiding important type qualifiers (like `const` or `volatile`) behind `[...]`.
The fix ensures that when template types differ only by qualifiers, those qualifiers are preserved in the diagnostic output rather than being elided, making the error messages much more actionable.
## Before changes error
<img width="1740" height="267" alt="Screenshot 2026-02-06 172130" src="https://github.com/user-attachments/assets/ef3d2d99-d2b1-4cde-8017-b41142004069" />
## After changes error
<img width="919" height="348" alt="Screenshot 2026-02-06 172337" src="https://github.com/user-attachments/assets/c458b47b-ef8a-4d07-84fa-677cce4be271" />
>From 31e6ffdd6275caacb8c03a890c607377c5b66dbe Mon Sep 17 00:00:00 2001
From: Mohit Gunani <gunanimohit1221 at gmail.com>
Date: Fri, 6 Feb 2026 17:10:56 +0530
Subject: [PATCH] [Clang] Improve template diffing to show qualifiers in elided
types
This change ensures that template diagnostics like Dual<int, [...]> vs Dual<const int, [...]> correctly display the differing qualifiers instead of hiding the entire type.
---
clang/lib/AST/ASTDiagnostic.cpp | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/clang/lib/AST/ASTDiagnostic.cpp b/clang/lib/AST/ASTDiagnostic.cpp
index b8023cb6fa10f..44983edbf870a 100644
--- a/clang/lib/AST/ASTDiagnostic.cpp
+++ b/clang/lib/AST/ASTDiagnostic.cpp
@@ -1205,8 +1205,16 @@ 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();
+ // ... your commented out lines ...
+ bool Same = false;
+ if (FromArgTST->getTemplateName().getAsTemplateDecl() ==
+ ToArgTST->getTemplateName().getAsTemplateDecl()) {
+ // If the names match, the ONLY thing that makes them different is the Qualifiers
+ Same = (FromQual == ToQual);
+ }
+ Tree.SetSame(Same);
Tree.SetTemplateDiff(FromArgTST->getTemplateName().getAsTemplateDecl(),
ToArgTST->getTemplateName().getAsTemplateDecl(),
FromQual, ToQual, FromDefault, ToDefault);
More information about the cfe-commits
mailing list