Author: Saar Raz Date: 2020-03-17T07:49:16+02:00 New Revision: 9e0bd5ec03cbc8d53048e92ddf7fd25bca17e912
URL: https://github.com/llvm/llvm-project/commit/9e0bd5ec03cbc8d53048e92ddf7fd25bca17e912 DIFF: https://github.com/llvm/llvm-project/commit/9e0bd5ec03cbc8d53048e92ddf7fd25bca17e912.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 { _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits