[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 14:24:28 PST 2022
royjacobson updated this revision to Diff 412252.
royjacobson added a comment.
Adding context.
(Sorry - didn't realize you were speaking about the diff itself, thought you meant adding general context to the PR message...)
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.412252.patch
Type: text/x-patch
Size: 1478 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220301/2baf5d91/attachment.bin>
More information about the cfe-commits
mailing list