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
}

0 commit comments

Comments
 (0)