Skip to content

Commit 7075eee

Browse files
authored
[clang][bytecode] Add InitLinkScope for toplevel Expr temporary (#123319)
1 parent a864906 commit 7075eee

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

clang/lib/AST/ByteCode/Compiler.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4247,6 +4247,7 @@ bool Compiler<Emitter>::visitExpr(const Expr *E, bool DestroyToplevelScope) {
42474247
// For us, that means everything we don't
42484248
// have a PrimType for.
42494249
if (std::optional<unsigned> LocalOffset = this->allocateLocal(E)) {
4250+
InitLinkScope<Emitter> ILS(this, InitLink::Temp(*LocalOffset));
42504251
if (!this->emitGetPtrLocal(*LocalOffset, E))
42514252
return false;
42524253

clang/test/AST/ByteCode/cxx20.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -893,3 +893,18 @@ namespace VirtDtor {
893893

894894
static_assert(test('C', 'B'));
895895
}
896+
897+
namespace TemporaryInNTTP {
898+
template<auto n> struct B { /* ... */ };
899+
struct J1 {
900+
J1 *self=this;
901+
};
902+
/// FIXME: The bytecode interpreter emits a different diagnostic here.
903+
/// The current interpreter creates a fake MaterializeTemporaryExpr (see EvaluateAsConstantExpr)
904+
/// which is later used as the LValueBase of the created APValue.
905+
B<J1{}> j1; // ref-error {{pointer to temporary object is not allowed in a template argument}} \
906+
// expected-error {{non-type template argument is not a constant expression}} \
907+
// expected-note {{pointer to temporary is not a constant expression}} \
908+
// expected-note {{created here}}
909+
B<2> j2; /// Ok.
910+
}

0 commit comments

Comments
 (0)