[llvm-branch-commits] [clang] 9fbd4ab - [Concepts] Do not check constraints if not all template arguments have been deduced

Saar Raz via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Wed Feb 12 06:03:32 PST 2020


Author: Saar Raz
Date: 2020-02-12T16:03:13+02:00
New Revision: 9fbd4ab395f73209d09d821f6e5d49150c1e36ab

URL: https://github.com/llvm/llvm-project/commit/9fbd4ab395f73209d09d821f6e5d49150c1e36ab
DIFF: https://github.com/llvm/llvm-project/commit/9fbd4ab395f73209d09d821f6e5d49150c1e36ab.diff

LOG: [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 5fef14d932fe602bf998b8fb8a809ff85ca1e245)

Added: 
    clang/test/CXX/temp/temp.deduct/p5.cpp

Modified: 
    clang/lib/Sema/SemaTemplateDeduction.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaTemplateDeduction.cpp b/clang/lib/Sema/SemaTemplateDeduction.cpp
index 1a71f270679d..6b865a601f9d 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 <typename T> concept C = true;
+void bar(C auto foo);
+int y = bar(
\ No newline at end of file


        


More information about the llvm-branch-commits mailing list