Skip to content

Commit c4a1e0e

Browse files
committed
[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>".
1 parent 8cb4485 commit c4a1e0e

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

clang/lib/AST/ASTDiagnostic.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1899,11 +1899,17 @@ class TemplateDiff {
18991899

19001900
E = E->IgnoreImpCasts();
19011901

1902-
if (isa<IntegerLiteral>(E)) return false;
1902+
auto CheckIntegerLiteral = [](Expr *E) {
1903+
if (auto *TemplateExpr = dyn_cast<SubstNonTypeTemplateParmExpr>(E))
1904+
E = TemplateExpr->getReplacement();
1905+
return isa<IntegerLiteral>(E);
1906+
};
1907+
1908+
if (CheckIntegerLiteral(E)) return false;
19031909

19041910
if (UnaryOperator *UO = dyn_cast<UnaryOperator>(E))
19051911
if (UO->getOpcode() == UO_Minus)
1906-
if (isa<IntegerLiteral>(UO->getSubExpr()))
1912+
if (CheckIntegerLiteral(UO->getSubExpr()))
19071913
return false;
19081914

19091915
if (isa<CXXBoolLiteralExpr>(E))

clang/test/Misc/diag-template-diffing-cxx98.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,35 @@ namespace qualifiers {
4747

4848
// CHECK: candidate template ignored: deduced conflicting types for parameter 'T' ('const vector<...>' vs. 'volatile vector<...>')
4949
}
50+
51+
namespace integers {
52+
template <int x>
53+
class wrapper{};
54+
55+
template <int x>
56+
class foo {
57+
public:
58+
wrapper<x> make();
59+
};
60+
61+
wrapper<1> w1 = foo<2>().make();
62+
// CHECK: no viable conversion from 'wrapper<2>' to 'wrapper<1>'
63+
64+
wrapper<1> w2 = foo<-3>().make();
65+
// CHECK: no viable conversion from 'wrapper<-3>' to 'wrapper<1>'
66+
67+
template <int x>
68+
wrapper<x> make();
69+
70+
wrapper<1> w3 = make<4>();
71+
// CHECK: no viable conversion from 'wrapper<4>' to 'wrapper<1>'
72+
73+
template <int x>
74+
wrapper<-x> makeNegative();
75+
76+
wrapper<1> w4 = makeNegative<5>();
77+
// CHECK: no viable conversion from 'wrapper<-5>' to 'wrapper<1>'
78+
79+
wrapper<1> w5 = makeNegative<-6>();
80+
// CHECK: no viable conversion from 'wrapper<6>' to 'wrapper<1>'
81+
}

0 commit comments

Comments
 (0)