[PATCH] D128351: [clang] missing outer template levels when checking template constraints

Sirui Mu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 22 08:56:14 PDT 2022


Lancern created this revision.
Lancern added reviewers: Richard, smith.
Herald added a project: All.
Lancern requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

When checking constraint satisfaction on template arguments, the outer
template levels are not added to MultiLevelTemplateArgumentList.

Fix bugs https://github.com/llvm/llvm-project/issues/50845


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D128351

Files:
  clang/lib/Sema/SemaConcept.cpp
  clang/test/Sema/template-member-constraint.cpp


Index: clang/test/Sema/template-member-constraint.cpp
===================================================================
--- /dev/null
+++ clang/test/Sema/template-member-constraint.cpp
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 %s -std=c++20 -fsyntax-only -verify
+
+template <typename T>
+concept Foo = true;
+
+template <typename T, typename U>
+struct Bar {};
+
+template <typename T>
+struct Baz {
+  template <Foo U>
+  using BazBar = Bar<T, U>;
+
+  using BazBarInt = BazBar<int>; // expected-no-diagnostics
+};
+
+template <typename urng_t>
+struct contiguous_range {
+  template <bool const_range>
+    requires(const_range == false)
+  using basic_iterator = int;
+
+  auto begin() {
+    return basic_iterator<false>{}; // expected-no-diagnostics
+  }
+};
Index: clang/lib/Sema/SemaConcept.cpp
===================================================================
--- clang/lib/Sema/SemaConcept.cpp
+++ clang/lib/Sema/SemaConcept.cpp
@@ -293,6 +293,7 @@
 
   MultiLevelTemplateArgumentList MLTAL;
   MLTAL.addOuterTemplateArguments(TemplateArgs);
+  MLTAL.addOuterRetainedLevels(Template->getTemplateDepth());
 
   for (const Expr *ConstraintExpr : ConstraintExprs) {
     if (calculateConstraintSatisfaction(S, Template, TemplateArgs,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D128351.439039.patch
Type: text/x-patch
Size: 1240 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220622/6784d37b/attachment.bin>


More information about the cfe-commits mailing list