[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>".
This commit is contained in:
Richard Trieu
2024-12-01 19:21:42 -08:00
parent 8cb44859cc
commit c4a1e0efe6
2 changed files with 40 additions and 2 deletions

View File

@@ -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))

View File

@@ -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>'
}