diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp b/clang/lib/Sema/SemaTemplateInstantiate.cpp --- a/clang/lib/Sema/SemaTemplateInstantiate.cpp +++ b/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()) continue; diff --git a/clang/test/SemaTemplate/constraints-instantiation.cpp b/clang/test/SemaTemplate/constraints-instantiation.cpp new file mode 100644 --- /dev/null +++ b/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 +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>; +}