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.
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);
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 {