[PATCH] D120255: [Concepts] Check constraints for explicit template instantiations

Roy Jacobson via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 1 13:52:20 PST 2022


royjacobson updated this revision to Diff 412229.
royjacobson edited the summary of this revision.
royjacobson set the repository for this revision to rG LLVM Github Monorepo.
royjacobson added a comment.
Herald added projects: clang, All.

Updated test so it checks actual instantiation and update the description.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D120255/new/

https://reviews.llvm.org/D120255

Files:
  clang/lib/Sema/SemaTemplateInstantiate.cpp
  clang/test/SemaTemplate/constraints-instantiation.cpp


Index: clang/test/SemaTemplate/constraints-instantiation.cpp
===================================================================
--- /dev/null
+++ clang/test/SemaTemplate/constraints-instantiation.cpp
@@ -0,0 +1,24 @@
+// RUN: %clang_cc1 -S -std=c++20 -emit-llvm %s -o - | FileCheck %s
+
+// void PR46029::A<1>::f()
+// CHECK: define {{.*}} @_ZN7PR460291AILi1EE1fEv
+// void PR46029::A<2>::f()
+// CHECK: define {{.*}} @_ZN7PR460291AILi2EE1fEv
+// void PR46029::A<3>::f()
+// CHECK-NOT: define {{.*}} @_ZN7PR460291AILi3EE1fEv
+
+namespace PR46029 {
+template <int N>
+struct A {
+  void f() requires(N == 1) {
+    static_assert(N == 1);
+  }
+  void f() requires(N == 2) {
+    static_assert(N == 2);
+  }
+};
+
+template struct A<1>;
+template struct A<2>;
+template struct A<3>;
+}
Index: clang/lib/Sema/SemaTemplateInstantiate.cpp
===================================================================
--- clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -3230,6 +3230,14 @@
       if (FunctionDecl *Pattern =
               Function->getInstantiatedFromMemberFunction()) {

+        if (Function->getTrailingRequiresClause()) {
+          ConstraintSatisfaction Satisfaction;
+          if (CheckFunctionConstraints(Function, Satisfaction) ||
+              !Satisfaction.IsSatisfied) {
+            continue;
+          }
+        }
+
         if (Function->hasAttr<ExcludeFromExplicitInstantiationAttr>())
           continue;



-------------- next part --------------
A non-text attachment was scrubbed...
Name: D120255.412229.patch
Type: text/x-patch
Size: 1476 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220301/2ebca5c0/attachment.bin>


More information about the cfe-commits mailing list