[clang] c4a1e0e - [clang] Remove redundant integer values in template type diffing
Richard Trieu via cfe-commits
cfe-commits at lists.llvm.org
Sun Dec 1 20:11:16 PST 2024
Author: Richard Trieu
Date: 2024-12-01T19:21:42-08:00
New Revision: c4a1e0efe6b0767dfb5861a7e8814d7db0c0de8a
URL: https://github.com/llvm/llvm-project/commit/c4a1e0efe6b0767dfb5861a7e8814d7db0c0de8a
DIFF: https://github.com/llvm/llvm-project/commit/c4a1e0efe6b0767dfb5861a7e8814d7db0c0de8a.diff
LOG: [clang] Remove redundant integer values in template type diffing
Look through SubstNonTypeTemplateParmExpr to find an IntegerLiteral
node when attempting to determine if extra info is printed via
the aka mechanism. This will avoid printing types such as
"array<5 aka 5>" and will only show "array<5>".
Added:
Modified:
clang/lib/AST/ASTDiagnostic.cpp
clang/test/Misc/diag-template-diffing-cxx98.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/ASTDiagnostic.cpp b/clang/lib/AST/ASTDiagnostic.cpp
index 4f677b60e60dae..7b873ee9833b34 100644
--- a/clang/lib/AST/ASTDiagnostic.cpp
+++ b/clang/lib/AST/ASTDiagnostic.cpp
@@ -1899,11 +1899,17 @@ class TemplateDiff {
E = E->IgnoreImpCasts();
- if (isa<IntegerLiteral>(E)) return false;
+ auto CheckIntegerLiteral = [](Expr *E) {
+ if (auto *TemplateExpr = dyn_cast<SubstNonTypeTemplateParmExpr>(E))
+ E = TemplateExpr->getReplacement();
+ return isa<IntegerLiteral>(E);
+ };
+
+ if (CheckIntegerLiteral(E)) return false;
if (UnaryOperator *UO = dyn_cast<UnaryOperator>(E))
if (UO->getOpcode() == UO_Minus)
- if (isa<IntegerLiteral>(UO->getSubExpr()))
+ if (CheckIntegerLiteral(UO->getSubExpr()))
return false;
if (isa<CXXBoolLiteralExpr>(E))
diff --git a/clang/test/Misc/diag-template-
diff ing-cxx98.cpp b/clang/test/Misc/diag-template-
diff ing-cxx98.cpp
index 7b1a08c6b86915..888b9f8b0e5e3d 100644
--- a/clang/test/Misc/diag-template-
diff ing-cxx98.cpp
+++ b/clang/test/Misc/diag-template-
diff ing-cxx98.cpp
@@ -47,3 +47,35 @@ namespace qualifiers {
// CHECK: candidate template ignored: deduced conflicting types for parameter 'T' ('const vector<...>' vs. 'volatile vector<...>')
}
+
+namespace integers {
+ template <int x>
+ class wrapper{};
+
+ template <int x>
+ class foo {
+ public:
+ wrapper<x> make();
+ };
+
+ wrapper<1> w1 = foo<2>().make();
+ // CHECK: no viable conversion from 'wrapper<2>' to 'wrapper<1>'
+
+ wrapper<1> w2 = foo<-3>().make();
+ // CHECK: no viable conversion from 'wrapper<-3>' to 'wrapper<1>'
+
+ template <int x>
+ wrapper<x> make();
+
+ wrapper<1> w3 = make<4>();
+ // CHECK: no viable conversion from 'wrapper<4>' to 'wrapper<1>'
+
+ template <int x>
+ wrapper<-x> makeNegative();
+
+ wrapper<1> w4 = makeNegative<5>();
+ // CHECK: no viable conversion from 'wrapper<-5>' to 'wrapper<1>'
+
+ wrapper<1> w5 = makeNegative<-6>();
+ // CHECK: no viable conversion from 'wrapper<6>' to 'wrapper<1>'
+}
More information about the cfe-commits
mailing list