diff --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp index 39169664dad55..290e4cbff4fd6 100755 --- a/clang/lib/Sema/SemaConcept.cpp +++ b/clang/lib/Sema/SemaConcept.cpp @@ -329,6 +329,13 @@ bool Sema::CheckFunctionConstraints(const FunctionDecl *FD, Satisfaction.IsSatisfied = true; return false; } + Qualifiers ThisQuals; + CXXRecordDecl *Record = nullptr; + if (auto *Method = dyn_cast(FD)) { + ThisQuals = Method->getMethodQualifiers(); + Record = const_cast(Method->getParent()); + } + CXXThisScopeRAII ThisScope(*this, Record, ThisQuals, Record != nullptr); // We substitute with empty arguments in order to rebuild the atomic // constraint in a constant-evaluated context. // FIXME: Should this be a dedicated TreeTransform? diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp index 0e1d5fa77c693..7094462e74c9c 100755 --- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -4271,7 +4271,13 @@ bool Sema::CheckInstantiatedFunctionTemplateConstraints( Scope, MLTAL)) return true; } - + Qualifiers ThisQuals; + CXXRecordDecl *Record = nullptr; + if (auto *Method = dyn_cast(Decl)) { + ThisQuals = Method->getMethodQualifiers(); + Record = Method->getParent(); + } + CXXThisScopeRAII ThisScope(*this, Record, ThisQuals, Record != nullptr); return CheckConstraintSatisfaction(Template, TemplateAC, TemplateArgs, PointOfInstantiation, Satisfaction); } diff --git a/clang/test/SemaTemplate/instantiate-requires-clause.cpp b/clang/test/SemaTemplate/instantiate-requires-clause.cpp index 8e9d5bffa9068..a4d1b65972019 100644 --- a/clang/test/SemaTemplate/instantiate-requires-clause.cpp +++ b/clang/test/SemaTemplate/instantiate-requires-clause.cpp @@ -57,4 +57,13 @@ struct S3 { static constexpr void f(Args...) { } }; -static_assert((S3::f(), true)); \ No newline at end of file +static_assert((S3::f(), true)); + +template +struct S4 { + template + constexpr void foo() requires (*this, true) { } + constexpr void goo() requires (*this, true) { } +}; + +static_assert((S4{}.foo(), S4{}.goo(), true));