diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp index 0fc942a4f1bc4..46545a5b3267e 100644 --- a/clang/lib/AST/ByteCode/Compiler.cpp +++ b/clang/lib/AST/ByteCode/Compiler.cpp @@ -3287,6 +3287,7 @@ template bool Compiler::visit(const Expr *E) { if (!this->emitGetPtrLocal(*LocalIndex, E)) return false; + InitLinkScope ILS(this, InitLink::Temp(*LocalIndex)); return this->visitInitializer(E); } @@ -4254,9 +4255,6 @@ bool Compiler::VisitCXXThisExpr(const CXXThisExpr *E) { // instance pointer of the current function frame, but e.g. to the declaration // currently being initialized. Here we emit the necessary instruction(s) for // this scenario. - if (!InitStackActive || !E->isImplicit()) - return this->emitThis(E); - if (InitStackActive && !InitStack.empty()) { unsigned StartIndex = 0; for (StartIndex = InitStack.size() - 1; StartIndex > 0; --StartIndex) { diff --git a/clang/test/AST/ByteCode/records.cpp b/clang/test/AST/ByteCode/records.cpp index 7e3cf5b94518f..2799afa9577b7 100644 --- a/clang/test/AST/ByteCode/records.cpp +++ b/clang/test/AST/ByteCode/records.cpp @@ -1653,3 +1653,9 @@ namespace ExprWithCleanups { constexpr auto F = true ? 1i : 2i; static_assert(F == 1i, ""); } + +namespace ExplicitThisInTemporary { + struct B { B *p = this; }; + constexpr bool g(B b) { return &b == b.p; } + static_assert(g({}), ""); +}