[llvm-branch-commits] [clang] a36a14b - [Concepts] Fix incorrect DeclContext for transformed RequiresExprBodyDecl
Hans Wennborg via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Thu Mar 19 02:25:44 PDT 2020
Author: Saar Raz
Date: 2020-03-19T10:18:56+01:00
New Revision: a36a14b70f18b156cea8552fd4b138487340ba76
URL: https://github.com/llvm/llvm-project/commit/a36a14b70f18b156cea8552fd4b138487340ba76
DIFF: https://github.com/llvm/llvm-project/commit/a36a14b70f18b156cea8552fd4b138487340ba76.diff
LOG: [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)
Added:
Modified:
clang/lib/Sema/TreeTransform.h
clang/test/SemaTemplate/instantiate-requires-expr.cpp
Removed:
################################################################################
diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index 805fe6684205..0305954a278e 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 927bc1bf8f12..ba82fc1313fc 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 {
More information about the llvm-branch-commits
mailing list