[PATCH] D128276: clang: perform deduction at the right depth on Sema::AddMethodTemplateCandidate

Matheus Izvekov via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 21 12:29:41 PDT 2022


mizvekov created this revision.
Herald added a project: All.
mizvekov updated this revision to Diff 438697.
mizvekov added a comment.
mizvekov published this revision for review.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

.


Fixes PR28087.

Signed-off-by: Matheus Izvekov <mizvekov at gmail.com>


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D128276

Files:
  clang/lib/Sema/SemaOverload.cpp
  clang/test/CXX/temp/temp.decls/temp.variadic/p5-cxx20.cpp


Index: clang/test/CXX/temp/temp.decls/temp.variadic/p5-cxx20.cpp
===================================================================
--- /dev/null
+++ clang/test/CXX/temp/temp.decls/temp.variadic/p5-cxx20.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s
+// expected-no-diagnostics
+
+namespace pr28087 {
+template <typename F> auto apply(F f) { f(); }
+template <class...> struct S {
+  template <int> auto f(decltype(apply([](auto...) {})));
+};
+template struct S<>;
+} // namespace pr28087
Index: clang/lib/Sema/SemaOverload.cpp
===================================================================
--- clang/lib/Sema/SemaOverload.cpp
+++ clang/lib/Sema/SemaOverload.cpp
@@ -7078,7 +7078,8 @@
   //   functions. In such a case, the candidate functions generated from each
   //   function template are combined with the set of non-template candidate
   //   functions.
-  TemplateDeductionInfo Info(CandidateSet.getLocation());
+  TemplateDeductionInfo Info(CandidateSet.getLocation(),
+                             MethodTmpl->getTemplateParameters()->getDepth());
   FunctionDecl *Specialization = nullptr;
   ConversionSequenceList Conversions;
   if (TemplateDeductionResult Result = DeduceTemplateArguments(
@@ -14118,8 +14119,12 @@
       IsError |= InputInit.isInvalid();
       Arg = InputInit.getAs<Expr>();
     } else {
-      ExprResult DefArg =
-          S.BuildCXXDefaultArgExpr(LParenLoc, Method, Method->getParamDecl(i));
+      ParmVarDecl *Param = Method->getParamDecl(i);
+      if (!Param->hasDefaultArg()) {
+        IsError = true;
+        break;
+      }
+      ExprResult DefArg = S.BuildCXXDefaultArgExpr(LParenLoc, Method, Param);
       if (DefArg.isInvalid()) {
         IsError = true;
         break;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D128276.438697.patch
Type: text/x-patch
Size: 1763 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220621/6b69f972/attachment.bin>


More information about the cfe-commits mailing list