diff options
| author | Saar Raz <saar@raz.email> | 2020-02-05 00:51:40 +0200 |
|---|---|---|
| committer | Saar Raz <saar@raz.email> | 2020-02-05 01:11:08 +0200 |
| commit | 8f19f984f296c8ddbb16dc1623e8a4bd6bfed111 (patch) | |
| tree | 36dedcb0297ce35e30e39986d44bb8c70f72147d | |
| parent | 7a94fc09d17bc317032eb9605eba05dced8c87e5 (diff) | |
| download | bcm5719-llvm-8f19f984f296c8ddbb16dc1623e8a4bd6bfed111.tar.gz bcm5719-llvm-8f19f984f296c8ddbb16dc1623e8a4bd6bfed111.zip | |
[Concepts] Add missing CXXThisScope to function template constraint substitution
We did not have a CXXThisScope around constraint checking of functions and
function template specializations, causing a crash when checking a constraint
that had a 'this' (bug 44689).
Recommit after fixing test.
(cherry picked from commit 6c232441564f8934477e418347bf0c217abb0a00)
| -rwxr-xr-x | clang/lib/Sema/SemaConcept.cpp | 7 | ||||
| -rwxr-xr-x | clang/lib/Sema/SemaTemplateInstantiateDecl.cpp | 8 | ||||
| -rw-r--r-- | clang/test/SemaTemplate/instantiate-requires-clause.cpp | 11 |
3 files changed, 24 insertions, 2 deletions
diff --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp index 39169664dad..290e4cbff4f 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<CXXMethodDecl>(FD)) { + ThisQuals = Method->getMethodQualifiers(); + Record = const_cast<CXXRecordDecl *>(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 0e1d5fa77c6..7094462e74c 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<CXXMethodDecl>(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 8e9d5bffa90..a4d1b659720 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<int>::f(), true));
\ No newline at end of file +static_assert((S3<int>::f(), true)); + +template<typename T> +struct S4 { + template<typename> + constexpr void foo() requires (*this, true) { } + constexpr void goo() requires (*this, true) { } +}; + +static_assert((S4<int>{}.foo<int>(), S4<int>{}.goo(), true)); |

