Skip to content

Commit 9fbd4ab

Browse files
committed
[Concepts] Do not check constraints if not all template arguments have been deduced
We previously checked the constraints of instantiated function templates even in cases where PartialOverloading was true and not all template arguments have been deduced, which caused crashes in clangd (bug 44714). We now check if all arguments have been deduced before checking constraints in partial overloading scenarios. (cherry picked from commit 5fef14d)
1 parent 2804f35 commit 9fbd4ab

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

clang/lib/Sema/SemaTemplateDeduction.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3439,13 +3439,16 @@ Sema::TemplateDeductionResult Sema::FinishTemplateArgumentDeduction(
34393439
// ([temp.constr.decl]), those constraints are checked for satisfaction
34403440
// ([temp.constr.constr]). If the constraints are not satisfied, type
34413441
// deduction fails.
3442-
if (CheckInstantiatedFunctionTemplateConstraints(Info.getLocation(),
3443-
Specialization, Builder, Info.AssociatedConstraintsSatisfaction))
3444-
return TDK_MiscellaneousDeductionFailure;
3442+
if (!PartialOverloading ||
3443+
(Builder.size() == FunctionTemplate->getTemplateParameters()->size())) {
3444+
if (CheckInstantiatedFunctionTemplateConstraints(Info.getLocation(),
3445+
Specialization, Builder, Info.AssociatedConstraintsSatisfaction))
3446+
return TDK_MiscellaneousDeductionFailure;
34453447

3446-
if (!Info.AssociatedConstraintsSatisfaction.IsSatisfied) {
3447-
Info.reset(TemplateArgumentList::CreateCopy(Context, Builder));
3448-
return TDK_ConstraintsNotSatisfied;
3448+
if (!Info.AssociatedConstraintsSatisfaction.IsSatisfied) {
3449+
Info.reset(TemplateArgumentList::CreateCopy(Context, Builder));
3450+
return TDK_ConstraintsNotSatisfied;
3451+
}
34493452
}
34503453

34513454
if (OriginalCallArgs) {
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// RUN: %clang_cc1 -std=c++2a -verify %s -code-completion-at=%s:6:16
2+
// expected-no-diagnostics
3+
4+
template <typename T> concept C = true;
5+
void bar(C auto foo);
6+
int y = bar(

0 commit comments

Comments
 (0)