[clang] 5fef14d - [Concepts] Do not check constraints if not all template arguments have been deduced

Saar Raz via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 12 06:02:24 PST 2020


Author: Saar Raz
Date: 2020-02-12T16:02:12+02:00
New Revision: 5fef14d932fe602bf998b8fb8a809ff85ca1e245

URL: https://github.com/llvm/llvm-project/commit/5fef14d932fe602bf998b8fb8a809ff85ca1e245
DIFF: https://github.com/llvm/llvm-project/commit/5fef14d932fe602bf998b8fb8a809ff85ca1e245.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.

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 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 <typename T> concept C = true;
+void bar(C auto foo);
+int y = bar(
\ No newline at end of file


        


More information about the cfe-commits mailing list