Skip to content

Commit 9bdaa17

Browse files
author
Aidan
committed
simplified diagnostics
1 parent 199dc79 commit 9bdaa17

File tree

5 files changed

+25
-24
lines changed

5 files changed

+25
-24
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4871,13 +4871,13 @@ def note_ovl_candidate_inconsistent_deduction_types : Note<
48714871
"of conflicting types for parameter %0 (%1 of type $ vs. %3 of type $)|"
48724872
"%1 and %3 of conflicting types for parameter %0}2,4">;
48734873

4874-
def note_ovl_candidate_explicit_arg_mismatch_detail : Note<
4874+
def note_ovl_candidate_explicit_arg_mismatch : Note<
48754875
"candidate template ignored: invalid explicitly-specified argument"
48764876
"%select{"
4877-
"|: expected a type, but got value '%1'"
4878-
"|: expected constant of type %3 but got type %1"
4879-
"|: could not convert '%1' from %2 to %3"
4880-
"| for %ordinal4 template parameter}0">;
4877+
"|: %select{non-type|type}1 argument %select{'%3'|%3}1 is not compatible with "
4878+
"%select{non-type|type}2 parameter %select{%5|%4}2"
4879+
"|: could not convert '%3' from %4 to %5"
4880+
"| for %ordinal6 template parameter}0">;
48814881

48824882
def note_ovl_candidate_unsatisfied_constraints : Note<
48834883
"candidate template ignored: constraints not satisfied%0">;

clang/lib/Sema/SemaOverload.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11719,42 +11719,43 @@ static void DiagnoseBadDeduction(Sema &S, NamedDecl *Found, Decl *Templated,
1171911719
TemplateArgument FirstArg = *DeductionFailure.getFirstArg();
1172011720
TemplateArgument SecondArg = *DeductionFailure.getSecondArg();
1172111721

11722-
auto TupleResult = [&]() -> std::tuple<int, int, QualType> {
11722+
auto TupleResult = [&]() -> std::tuple<int, int, int, int, QualType> {
1172311723
switch (ParamD->getKind()) {
1172411724
case Decl::TemplateTypeParm: {
1172511725
auto *TTPD = cast<TemplateTypeParmDecl>(ParamD);
11726-
return {1, TTPD->getIndex(), QualType()};
11726+
return {1, 0, 1, TTPD->getIndex(), QualType()};
1172711727
}
1172811728
case Decl::NonTypeTemplateParm: {
1172911729
auto *NTTPD = cast<NonTypeTemplateParmDecl>(ParamD);
11730-
if (SecondArg.isNull())
11731-
return {2, NTTPD->getIndex(), NTTPD->getType()};
11732-
else {
11730+
if (SecondArg.isNull()) {
11731+
return {1, 1, 0, NTTPD->getIndex(), NTTPD->getType()};
11732+
} else {
1173311733
// FIXME: This is a hack. We should emit a better message
1173411734
// for ill-formed const exprs in >=C++20.
1173511735
QualType qt = NTTPD->getType();
1173611736
if (qt.getCanonicalType() ==
1173711737
SecondArg.getAsType().getCanonicalType() &&
1173811738
__cplusplus <= 201703) {
11739-
return {4, NTTPD->getIndex(), NTTPD->getType()};
11739+
return {3, -1, -1, NTTPD->getIndex(), NTTPD->getType()};
1174011740
} else {
11741-
return {3, NTTPD->getIndex(), NTTPD->getType()};
11741+
return {2, -1, -1, NTTPD->getIndex(), NTTPD->getType()};
1174211742
}
1174311743
}
1174411744
}
1174511745
case Decl::TemplateTemplateParm: {
1174611746
auto *TTempPD = cast<TemplateTemplateParmDecl>(ParamD);
11747-
return {4, TTempPD->getIndex(), QualType()};
11747+
return {3, -1, -1, TTempPD->getIndex(), QualType()};
1174811748
}
1174911749
default:
1175011750
llvm_unreachable("unexpected param decl kind");
1175111751
}
1175211752
};
11753-
auto [Which, Index, Type] = TupleResult();
11753+
auto [Which, Provided, Expected, Index, Type] = TupleResult();
1175411754
S.NoteTemplateParameterLocation(*ParamD);
1175511755
S.Diag(Templated->getLocation(),
11756-
diag::note_ovl_candidate_explicit_arg_mismatch_detail)
11757-
<< Which << FirstArg << SecondArg << Type << (Index + 1);
11756+
diag::note_ovl_candidate_explicit_arg_mismatch)
11757+
<< Which << Provided << Expected << FirstArg << SecondArg << Type
11758+
<< (Index + 1);
1175811759

1175911760
MaybeEmitInheritedConstructorNote(S, Found);
1176011761
return;

clang/test/CXX/dcl.dcl/basic.namespace/namespace.udecl/p12.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,21 +113,21 @@ namespace test3 {
113113

114114
struct Derived1 : Base {
115115
using Base::foo;
116-
template <int n> Opaque<2> foo() { return Opaque<2>(); } // expected-note{{template parameter is declared here}} // expected-note {{candidate template ignored: invalid explicitly-specified argument: expected constant of type 'int' but got type 'int'}}
116+
template <int n> Opaque<2> foo() { return Opaque<2>(); } // expected-note{{template parameter is declared here}} // expected-note {{candidate template ignored: invalid explicitly-specified argument: type argument 'int' is not compatible with non-type parameter 'int'}}
117117
};
118118

119119
struct Derived2 : Base {
120-
template <int n> Opaque<2> foo() { return Opaque<2>(); } // expected-note{{template parameter is declared here}} // expected-note {{candidate template ignored: invalid explicitly-specified argument: expected constant of type 'int' but got type 'int'}}
120+
template <int n> Opaque<2> foo() { return Opaque<2>(); } // expected-note{{template parameter is declared here}} // expected-note {{candidate template ignored: invalid explicitly-specified argument: type argument 'int' is not compatible with non-type parameter 'int'}}
121121
using Base::foo;
122122
};
123123

124124
struct Derived3 : Base {
125125
using Base::foo;
126-
template <class T> Opaque<3> foo() { return Opaque<3>(); } // expected-note{{template parameter is declared here}} // expected-note {{candidate template ignored: invalid explicitly-specified argument: expected a type, but got value '0'}}
126+
template <class T> Opaque<3> foo() { return Opaque<3>(); } // expected-note{{template parameter is declared here}} // expected-note {{candidate template ignored: invalid explicitly-specified argument: non-type argument '0' is not compatible with type parameter 'int'}}
127127
};
128128

129129
struct Derived4 : Base {
130-
template <class T> Opaque<3> foo() { return Opaque<3>(); } // expected-note{{template parameter is declared here}} // expected-note {{candidate template ignored: invalid explicitly-specified argument: expected a type, but got value '0'}}
130+
template <class T> Opaque<3> foo() { return Opaque<3>(); } // expected-note{{template parameter is declared here}} // expected-note {{andidate template ignored: invalid explicitly-specified argument: non-type argument '0' is not compatible with type parameter 'int'}}
131131
using Base::foo;
132132
};
133133

clang/test/CXX/drs/cwg2xx.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -650,12 +650,12 @@ namespace cwg241 { // cwg241: 9
650650
C::f<3>(b);
651651
// expected-error@-1 {{no matching function for call to 'f'}}
652652
// expected-note@#cwg241-C-f 2{{template parameter is declared here}}
653-
// expected-note@#cwg241-C-f 2{{candidate template ignored: invalid explicitly-specified argument: expected a type, but got value '3}}
653+
// expected-note@#cwg241-C-f 2{{candidate template ignored: invalid explicitly-specified argument: non-type argument '3' is not compatible with type parameter 'int'}}
654654

655655
C::g<3>(b);
656656
// expected-error@-1 {{no matching function for call to 'g'}}
657657
// expected-note@#cwg241-C-g {{template parameter is declared here}}
658-
// expected-note@#cwg241-C-g {{candidate template ignored: invalid explicitly-specified argument: expected a type, but got value '3}}
658+
// expected-note@#cwg241-C-g {{candidate template ignored: invalid explicitly-specified argument: non-type argument '3' is not compatible with type parameter 'int'}}
659659

660660
using C::f;
661661
using C::g;
@@ -955,7 +955,7 @@ namespace cwg258 { // cwg258: 2.8
955955
int &x = b.g<int>(0);
956956
// expected-error@-1 {{no matching member function for call to 'g'}}
957957
// expected-note@#cwg258-B-g {{template parameter is declared here}}
958-
// expected-note@#cwg258-B-g {{candidate template ignored: invalid explicitly-specified argument: expected constant of type 'int' but got type 'int'}}
958+
// expected-note@#cwg258-B-g {{candidate template ignored: invalid explicitly-specified argument: type argument 'int' is not compatible with non-type parameter 'int'}}
959959
int &y = b.h();
960960
float &z = const_cast<const B&>(b).h();
961961

clang/test/SemaTemplate/overload-candidates.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ void test_dyn_cast(int* ptr) {
1818

1919
template<int I, typename T> // expected-note {{template parameter is declared here}}
2020
void get(const T&); // #get-int-typename
21-
// expected-note@#get-int-typename {{candidate template ignored: invalid explicitly-specified argument: expected constant of type 'int' but got type 'int'}}
21+
// expected-note@#get-int-typename {{candidate template ignored: invalid explicitly-specified argument: type argument 'int' is not compatible with non-type parameter 'int'}}
2222
template<template<class T> class, typename T> // expected-note {{template parameter is declared here}}
2323
void get(const T&); // expected-note {{candidate template ignored: invalid explicitly-specified argument for 1st template parameter}}
2424

0 commit comments

Comments
 (0)