diff options
author | Saar Raz <saar@raz.email> | 2020-03-10 23:17:00 +0200 |
---|---|---|
committer | Saar Raz <saar@raz.email> | 2020-03-17 07:49:16 +0200 |
commit | 9e0bd5ec03cbc8d53048e92ddf7fd25bca17e912 (patch) | |
tree | a2512ff3745a380c07b23053fca7603c297b4e0f | |
parent | 39930d67fffb086cabd08bccdc26ca6ad99b3339 (diff) | |
download | llvm-9e0bd5ec03cbc8d53048e92ddf7fd25bca17e912.zip llvm-9e0bd5ec03cbc8d53048e92ddf7fd25bca17e912.tar.gz llvm-9e0bd5ec03cbc8d53048e92ddf7fd25bca17e912.tar.bz2 |
[Concepts] Fix incorrect DeclContext for transformed RequiresExprBodyDecl
We would assign the incorrect DeclContext when transforming the RequiresExprBodyDecl, causing incorrect
handling of 'this' inside RequiresExprBodyDecls (bug #45162).
Assign the current context as the DeclContext of the transformed decl.
(cherry picked from commit 9769e1ee9acc33638449b50ac394b5ee2d4efb60)
-rw-r--r-- | clang/lib/Sema/TreeTransform.h | 2 | ||||
-rw-r--r-- | clang/test/SemaTemplate/instantiate-requires-expr.cpp | 13 |
2 files changed, 14 insertions, 1 deletions
diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h index 805fe66..0305954 100644 --- a/clang/lib/Sema/TreeTransform.h +++ b/clang/lib/Sema/TreeTransform.h @@ -11303,7 +11303,7 @@ TreeTransform<Derived>::TransformRequiresExpr(RequiresExpr *E) { SemaRef, Sema::ExpressionEvaluationContext::Unevaluated); RequiresExprBodyDecl *Body = RequiresExprBodyDecl::Create( - getSema().Context, E->getBody()->getDeclContext(), + getSema().Context, getSema().CurContext, E->getBody()->getBeginLoc()); Sema::ContextRAII SavedContext(getSema(), Body, /*NewThisContext*/false); diff --git a/clang/test/SemaTemplate/instantiate-requires-expr.cpp b/clang/test/SemaTemplate/instantiate-requires-expr.cpp index 927bc1b..ba82fc1 100644 --- a/clang/test/SemaTemplate/instantiate-requires-expr.cpp +++ b/clang/test/SemaTemplate/instantiate-requires-expr.cpp @@ -164,6 +164,19 @@ namespace expr_requirement { struct r3 {}; using r3i = r3<int, unsigned int>; // expected-error{{constraints not satisfied for class template 'r3' [with Ts = <int, unsigned int>]}} + + template<typename T> + struct r4 { + constexpr int foo() { + if constexpr (requires { this->invalid(); }) + return 1; + else + return 0; + } + + constexpr void invalid() requires false { } + }; + static_assert(r4<int>{}.foo() == 0); } namespace nested_requirement { |