From 5fef14d932fe602bf998b8fb8a809ff85ca1e245 Mon Sep 17 00:00:00 2001 From: Saar Raz Date: Wed, 12 Feb 2020 15:58:51 +0200 Subject: [PATCH] [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. --- clang/lib/Sema/SemaTemplateDeduction.cpp | 15 +++++++++------ clang/test/CXX/temp/temp.deduct/p5.cpp | 6 ++++++ 2 files changed, 15 insertions(+), 6 deletions(-) create mode 100644 clang/test/CXX/temp/temp.deduct/p5.cpp diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp b/clang/lib/Sema/SemaTemplateDeduction.cpp index 24019bf7975b..a0b92cdf3a5e 100644 --- a/clang/lib/Sema/SemaTemplateDeduction.cpp +++ b/clang/lib/Sema/SemaTemplateDeduction.cpp @@ -3439,13 +3439,16 @@ Sema::TemplateDeductionResult Sema::FinishTemplateArgumentDeduction( // ([temp.constr.decl]), those constraints are checked for satisfaction // ([temp.constr.constr]). If the constraints are not satisfied, type // deduction fails. - if (CheckInstantiatedFunctionTemplateConstraints(Info.getLocation(), - Specialization, Builder, Info.AssociatedConstraintsSatisfaction)) - return TDK_MiscellaneousDeductionFailure; + if (!PartialOverloading || + (Builder.size() == FunctionTemplate->getTemplateParameters()->size())) { + if (CheckInstantiatedFunctionTemplateConstraints(Info.getLocation(), + Specialization, Builder, Info.AssociatedConstraintsSatisfaction)) + return TDK_MiscellaneousDeductionFailure; - if (!Info.AssociatedConstraintsSatisfaction.IsSatisfied) { - Info.reset(TemplateArgumentList::CreateCopy(Context, Builder)); - return TDK_ConstraintsNotSatisfied; + if (!Info.AssociatedConstraintsSatisfaction.IsSatisfied) { + Info.reset(TemplateArgumentList::CreateCopy(Context, Builder)); + return TDK_ConstraintsNotSatisfied; + } } if (OriginalCallArgs) { diff --git a/clang/test/CXX/temp/temp.deduct/p5.cpp b/clang/test/CXX/temp/temp.deduct/p5.cpp new file mode 100644 index 000000000000..0c998b19f181 --- /dev/null +++ b/clang/test/CXX/temp/temp.deduct/p5.cpp @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -std=c++2a -verify %s -code-completion-at=%s:6:16 +// expected-no-diagnostics + +template concept C = true; +void bar(C auto foo); +int y = bar( \ No newline at end of file