Skip to content

Commit 3aa27cc

Browse files
committed
Rectify diagnostics
1 parent de90a38 commit 3aa27cc

15 files changed

+72
-45
lines changed

clang/lib/Sema/SemaTemplateDeduction.cpp

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3863,7 +3863,7 @@ TemplateDeductionResult Sema::FinishTemplateArgumentDeduction(
38633863
FD = const_cast<FunctionDecl *>(FDFriend);
38643864
Owner = FD->getLexicalDeclContext();
38653865
}
3866-
#if 1
3866+
// [DR2369]
38673867
// FIXME: We have to partially instantiate lambda's captures for constraint
38683868
// evaluation.
38693869
if (!isLambdaCallOperator(FD) && !isLambdaConversionOperator(FD) &&
@@ -3894,9 +3894,6 @@ TemplateDeductionResult Sema::FinishTemplateArgumentDeduction(
38943894
/*SkipForSpecialization=*/false,
38953895
/*Merged=*/&MLTAL);
38963896

3897-
// if (SetupConstraintScope(FD, SugaredBuilder, MLTAL, Scope))
3898-
// return TemplateDeductionResult::MiscellaneousDeductionFailure;
3899-
39003897
MultiLevelTemplateArgumentList JustTemplArgs(
39013898
Template, CanonicalDeducedArgumentList->asArray(),
39023899
/*Final=*/false);
@@ -3921,7 +3918,7 @@ TemplateDeductionResult Sema::FinishTemplateArgumentDeduction(
39213918
CXXThisScopeRAII ThisScope(*this, Record, ThisQuals, Record != nullptr);
39223919
llvm::SmallVector<Expr *, 1> Converted;
39233920
if (CheckConstraintSatisfaction(Template, TemplateAC, MLTAL,
3924-
Template->getSourceRange(),
3921+
Info.getLocation(),
39253922
Info.AssociatedConstraintsSatisfaction))
39263923
return TemplateDeductionResult::MiscellaneousDeductionFailure;
39273924
if (!Info.AssociatedConstraintsSatisfaction.IsSatisfied) {
@@ -3931,7 +3928,18 @@ TemplateDeductionResult Sema::FinishTemplateArgumentDeduction(
39313928
}
39323929
}
39333930
}
3934-
#endif
3931+
3932+
// C++ [temp.deduct.call]p10: [DR1391]
3933+
// If deduction succeeds for all parameters that contain
3934+
// template-parameters that participate in template argument deduction,
3935+
// and all template arguments are explicitly specified, deduced, or
3936+
// obtained from default template arguments, remaining parameters are then
3937+
// compared with the corresponding arguments. For each remaining parameter
3938+
// P with a type that was non-dependent before substitution of any
3939+
// explicitly-specified template arguments, if the corresponding argument
3940+
// A cannot be implicitly converted to P, deduction fails.
3941+
if (CheckNonDependent())
3942+
return TemplateDeductionResult::NonDependentConversionFailure;
39353943

39363944
MultiLevelTemplateArgumentList SubstArgs(
39373945
FunctionTemplate, CanonicalDeducedArgumentList->asArray(),
@@ -3982,18 +3990,6 @@ TemplateDeductionResult Sema::FinishTemplateArgumentDeduction(
39823990
}
39833991
}
39843992

3985-
// C++ [temp.deduct.call]p10: [DR1391]
3986-
// If deduction succeeds for all parameters that contain
3987-
// template-parameters that participate in template argument deduction,
3988-
// and all template arguments are explicitly specified, deduced, or
3989-
// obtained from default template arguments, remaining parameters are then
3990-
// compared with the corresponding arguments. For each remaining parameter
3991-
// P with a type that was non-dependent before substitution of any
3992-
// explicitly-specified template arguments, if the corresponding argument
3993-
// A cannot be implicitly converted to P, deduction fails.
3994-
if (CheckNonDependent())
3995-
return TemplateDeductionResult::NonDependentConversionFailure;
3996-
39973993
// We skipped the instantiation of the explicit-specifier during the
39983994
// substitution of `FD` before. So, we try to instantiate it back if
39993995
// `Specialization` is either a constructor or a conversion function.

clang/lib/Sema/SemaTemplateDeductionGuide.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -904,10 +904,12 @@ Expr *buildIsDeducibleConstraint(Sema &SemaRef,
904904
Context.getTrivialTypeSourceInfo(
905905
Context.getDeducedTemplateSpecializationType(
906906
TemplateName(AliasTemplate), /*DeducedType=*/QualType(),
907-
/*IsDependent=*/true)), // template specialization type whose
908-
// arguments will be deduced.
907+
/*IsDependent=*/true),
908+
AliasTemplate->getLocation()), // template specialization type whose
909+
// arguments will be deduced.
909910
Context.getTrivialTypeSourceInfo(
910-
ReturnType), // type from which template arguments are deduced.
911+
ReturnType, AliasTemplate->getLocation()), // type from which template
912+
// arguments are deduced.
911913
};
912914
return TypeTraitExpr::Create(
913915
Context, Context.getLogicalOperationType(), AliasTemplate->getLocation(),

clang/test/CXX/drs/cwg23xx.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,3 +392,35 @@ namespace cwg2397 { // cwg2397: 17
392392
} // namespace cwg2397
393393

394394
#endif
395+
396+
#if __cplusplus >= 202002L
397+
398+
namespace cwg2369 { // cwg2369: 20
399+
400+
template <class T> struct Z {
401+
typedef typename T::x xx;
402+
};
403+
404+
template <class T>
405+
concept C = requires { typename T::A; };
406+
template <C T> typename Z<T>::xx f(void *, T); // #1
407+
template <class T> void f(int, T); // #2
408+
409+
struct A {
410+
} a;
411+
412+
struct ZZ {
413+
template <class T, class = typename Z<T>::xx> operator T *();
414+
operator int();
415+
};
416+
417+
void foo() {
418+
ZZ zz;
419+
f(1, a); // OK, deduction fails for #1 because there is no conversion from int
420+
// to void*
421+
f(zz, 42); // OK, deduction fails for #1 because C<int> is not satisfied
422+
}
423+
424+
} // namespace cwg2369
425+
426+
#endif

clang/test/CXX/drs/cwg26xx.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ void f(T) requires requires { []() { T::invalid; } (); };
210210
// since-cxx20-note@-3 {{in instantiation of requirement here}}
211211
// since-cxx20-note@-4 {{while substituting template arguments into constraint expression here}}
212212
// since-cxx20-note@#cwg2672-f-0 {{while checking constraint satisfaction for template 'f<int>' required here}}
213-
// since-cxx20-note@#cwg2672-f-0 {{in instantiation of function template specialization 'cwg2672::f<int>' requested here}}
213+
// since-cxx20-note@#cwg2672-f-0 {{while substituting deduced template arguments into function template 'f' [with T = int]}}
214214
void f(...);
215215

216216
template <class T>

clang/test/CXX/expr/expr.prim/expr.prim.req/nested-requirement.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ void func() {
154154

155155
bar<int>();
156156
// expected-note@-1 {{while checking constraint satisfaction for template 'bar<int>' required here}} \
157-
// expected-note@-1 {{in instantiation of function template specialization}}
157+
// expected-note@-1 {{while substituting deduced template arguments into function template 'bar' [with T = int]}}
158158
// expected-note@#bar {{in instantiation of static data member}}
159159
// expected-note@#bar {{in instantiation of requirement here}}
160160
// expected-note@#bar {{while checking the satisfaction of nested requirement requested here}}

clang/test/CXX/temp/temp.constr/temp.constr.atomic/constrant-satisfaction-conversions.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ template<typename T> struct S {
1111

1212
// expected-error@+3{{atomic constraint must be of type 'bool' (found 'S<int>')}}
1313
// expected-note@#FINST{{while checking constraint satisfaction}}
14-
// expected-note@#FINST{{in instantiation of function template specialization}}
14+
// expected-note@#FINST{{while substituting deduced template arguments into function template 'f' [with T = int]}}
1515
template<typename T> requires (S<T>{})
1616
void f(T);
1717
void f(int);
1818

1919
// Ensure this applies to operator && as well.
2020
// expected-error@+3{{atomic constraint must be of type 'bool' (found 'S<int>')}}
2121
// expected-note@#F2INST{{while checking constraint satisfaction}}
22-
// expected-note@#F2INST{{in instantiation of function template specialization}}
22+
// expected-note@#F2INST{{while substituting deduced template arguments into function template 'f2' [with T = int]}}
2323
template<typename T> requires (S<T>{} && true)
2424
void f2(T);
2525
void f2(int);
@@ -32,7 +32,7 @@ template<typename T> requires requires {
3232
// expected-note@-4{{while checking the satisfaction}}
3333
// expected-note@-6{{while substituting template arguments}}
3434
// expected-note@#F3INST{{while checking constraint satisfaction}}
35-
// expected-note@#F3INST{{in instantiation of function template specialization}}
35+
// expected-note@#F3INST{{while substituting deduced template arguments into function template 'f3' [with T = int]}}
3636
//
3737
}
3838
void f3(T);

clang/test/SemaCXX/concept-crash-on-diagnostic.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ void function() {
3131
// expected-note@#3 {{checking the satisfaction of concept 'convertible_to<bool, bool>'}}
3232
// expected-note@#2 {{substituting template arguments into constraint expression here}}
3333
// expected-note@#5 {{checking constraint satisfaction for template 'compare<Object *, Object *>'}}
34-
// expected-note@#5 {{in instantiation of function template specialization 'compare<Object *, Object *>' requested here}}
34+
// expected-note@#5 {{while substituting deduced template arguments into function template 'compare' [with IteratorL = Object *, IteratorR = Object *]}}
3535

3636
// expected-note@#4 {{candidate template ignored: constraints not satisfied [with IteratorL = Object *, IteratorR = Object *]}}
3737
// We don't know exactly the substituted type for `lhs == rhs`, thus a placeholder 'expr-type' is emitted.

clang/test/SemaCXX/cxx20-ctad-type-alias.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ struct Foo {
196196

197197
template <int K>
198198
using Bar = Foo<double, K>; // expected-note {{constraints not satisfied for class template 'Foo'}}
199-
// expected-note@-1 {{candidate template ignored: could not match}}
199+
// expected-note@-1 {{candidate template ignored: could not match}} expected-note@-1 {{candidate template ignored: constraints not satisfied}}
200200
// expected-note@-2 {{implicit deduction guide declared as 'template <int K> requires __is_deducible(test14::Bar, Foo<double, K>) Bar(Foo<double, K>) -> Foo<double, K>'}}
201201
// expected-note@-3 {{implicit deduction guide declared as 'template <int K> requires __is_deducible(test14::Bar, Foo<double, K>) Bar(const double (&)[K]) -> Foo<double, K>'}}
202202
double abc[3];

clang/test/SemaCXX/cxx23-assume.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,12 @@ constexpr int f5() requires (!C<T>) { return 2; } // expected-note 4 {{while che
127127

128128
static_assert(f5<int>() == 1);
129129
static_assert(f5<D>() == 1); // expected-note 3 {{while checking constraint satisfaction}}
130-
// expected-note@-1 3 {{in instantiation of}}
130+
// expected-note@-1 3 {{while substituting deduced template arguments}}
131131
// expected-error@-2 {{no matching function for call}}
132132

133133
static_assert(f5<double>() == 2);
134-
static_assert(f5<E>() == 1); // expected-note {{while checking constraint satisfaction}} expected-note {{in instantiation of}}
135-
static_assert(f5<F>() == 2); // expected-note {{while checking constraint satisfaction}} expected-note {{in instantiation of}}
134+
static_assert(f5<E>() == 1); // expected-note {{while checking constraint satisfaction}} expected-note {{while substituting deduced template arguments}}
135+
static_assert(f5<F>() == 2); // expected-note {{while checking constraint satisfaction}} expected-note {{while substituting deduced template arguments}}
136136

137137
// Do not validate assumptions whose evaluation would have side-effects.
138138
constexpr int foo() {

clang/test/SemaCXX/cxx2c-fold-exprs.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ void g() {
233233
A<Thingy, Thingy> *ap;
234234
f(ap, ap); // expected-error{{no matching function for call to 'f'}} \
235235
// expected-note {{while checking constraint satisfaction}} \
236-
// expected-note {{in instantiation of function template specialization}}
236+
// expected-note {{while substituting deduced template arguments}}
237237
}
238238

239239
}

clang/test/SemaCXX/lambda-unevaluated.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ int* func(T) requires requires { []() { T::foo(); }; }; // expected-error{{type
172172
double* func(...);
173173

174174
static_assert(__is_same(decltype(func(0)), double*)); // expected-note {{while checking constraint satisfaction for template 'func<int>' required here}}
175-
// expected-note@-1 {{in instantiation of function template specialization 'lambda_in_constraints::func<int>'}}
175+
// expected-note@-1 {{while substituting deduced template arguments into function template 'func' [with T = int]}}
176176
static_assert(__is_same(decltype(func(WithFoo())), int*));
177177

178178
template <class T>
@@ -250,7 +250,7 @@ S s("a"); // #use
250250
// expected-note@#S-requires {{substituting template arguments into constraint expression here}}
251251
// expected-note@#S-requires {{in instantiation of requirement here}}
252252
// expected-note@#use {{checking constraint satisfaction for template 'S<const char *>' required here}}
253-
// expected-note@#use {{requested here}}
253+
// expected-note@#use {{while substituting deduced template arguments into function template 'S' [with value:auto = const char *]}}
254254
// expected-note-re@#S 2{{candidate constructor {{.*}} not viable}}
255255
// expected-note@#S-ctor {{constraints not satisfied}}
256256
// expected-note-re@#S-requires {{because {{.*}} would be invalid}}

clang/test/SemaTemplate/concepts-recursive-inst.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ auto it = begin(rng); // #BEGIN_CALL
7676
// expected-note@#INF_BEGIN {{while checking the satisfaction of concept 'Inf<struct my_range>' requested here}}
7777
// expected-note@#INF_BEGIN {{while substituting template arguments into constraint expression here}}
7878
// expected-note@#BEGIN_CALL {{while checking constraint satisfaction for template 'begin<struct my_range>' required here}}
79-
// expected-note@#BEGIN_CALL {{in instantiation of function template specialization}}
79+
// expected-note@#BEGIN_CALL {{while substituting deduced template arguments into function template}}
8080

8181
// Fallout of the failure is failed lookup, which is necessary to stop odd
8282
// cascading errors.
@@ -103,7 +103,7 @@ namespace GH50891 {
103103
// expected-note@#OP_TO {{while checking the satisfaction of concept 'Numeric<Deferred>' requested here}}
104104
// expected-note@#OP_TO {{while substituting template arguments into constraint expression here}}
105105
// expected-note@#FOO_CALL {{while checking constraint satisfaction for template}}
106-
// expected-note@#FOO_CALL {{in instantiation of function template specialization}}
106+
// expected-note@#FOO_CALL {{while substituting deduced template arguments into function template}}
107107
// expected-note@#FOO_CALL {{in instantiation of requirement here}}
108108
// expected-note@#NUMERIC {{while substituting template arguments into constraint expression here}}
109109

clang/test/SemaTemplate/cxx2a-constraint-exprs.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ namespace constant_evaluated {
3434
expected-note@-1{{candidate template ignored}}
3535
int a = (foo<int>(), 0);
3636
// expected-note@-1 {{while checking}} expected-error@-1{{no matching function}} \
37-
expected-note@-1 {{in instantiation}}
37+
expected-note@-1 {{while substituting}}
3838
template<typename T> void bar() requires requires { requires f<int[2]>; } { };
3939
// expected-note@-1{{in instantiation}} \
4040
expected-note@-1{{while substituting}} \

clang/test/SemaTemplate/deduction-guide.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -234,11 +234,6 @@ F s(0);
234234
// CHECK: | `-CXXBoolLiteralExpr {{.*}} 'bool' false
235235
// CHECK: |-CXXDeductionGuideDecl {{.*}} implicit <deduction guide for F> 'auto (U) -> F<>'
236236
// CHECK: | `-ParmVarDecl {{.*}} 'U'
237-
// CHECK: `-CXXDeductionGuideDecl {{.*}} implicit <deduction guide for F> 'auto (int) -> F<>'
238-
// CHECK: |-TemplateArgument integral ''x''
239-
// CHECK: |-TemplateArgument type 'int'
240-
// CHECK: | `-BuiltinType {{.*}} 'int'
241-
// CHECK: `-ParmVarDecl {{.*}} 'int'
242237
// CHECK: FunctionProtoType {{.*}} 'auto (U) -> F<>' dependent trailing_return cdecl
243238
// CHECK: |-InjectedClassNameType {{.*}} 'F<>' dependent
244239
// CHECK: | `-CXXRecord {{.*}} 'F'

clang/test/SemaTemplate/nested-implicit-deduction-guides.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ template<typename A, typename T>
3838
concept True = true;
3939

4040
template<typename T>
41-
concept False = false;
41+
concept False = false; // #False
4242

4343
template<class X> struct concepts {
4444
template<class Y> struct B {
@@ -68,7 +68,7 @@ template<typename X> struct nested_init_list {
6868
Y y;
6969
};
7070

71-
template<False F>
71+
template<False F> // #INIT_LIST_INNER_INVALID_HEADER
7272
struct concept_fail { // #INIT_LIST_INNER_INVALID
7373
X x;
7474
F f;
@@ -81,7 +81,9 @@ using NIL = nested_init_list<int>::B<int>;
8181

8282
// expected-error@+1 {{no viable constructor or deduction guide for deduction of template arguments of 'nested_init_list<int>::concept_fail'}}
8383
nested_init_list<int>::concept_fail nil_invalid{1, ""};
84-
// expected-note@#INIT_LIST_INNER_INVALID {{candidate template ignored: substitution failure [with F = const char *]: constraints not satisfied for class template 'concept_fail' [with F = const char *]}}
84+
// expected-note@#INIT_LIST_INNER_INVALID {{candidate template ignored: constraints not satisfied [with F = const char *]}}
85+
// expected-note@#INIT_LIST_INNER_INVALID_HEADER {{because 'const char *' does not satisfy 'False'}}
86+
// expected-note@#False {{because 'false' evaluated to false}}
8587
// expected-note@#INIT_LIST_INNER_INVALID {{implicit deduction guide declared as 'template <False F> concept_fail(int, F) -> concept_fail<F>'}}
8688
// expected-note@#INIT_LIST_INNER_INVALID {{candidate function template not viable: requires 1 argument, but 2 were provided}}
8789
// expected-note@#INIT_LIST_INNER_INVALID {{implicit deduction guide declared as 'template <False F> concept_fail(concept_fail<F>) -> concept_fail<F>'}}

0 commit comments

Comments
 (0)