[clang] [clang][bytecode] Add InitLinkScope for toplevel Expr temporary (PR #123319)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Fri Jan 17 02:52:20 PST 2025
https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/123319
None
>From d20a37fcaebf999167ffceeb417e0369ef8a9936 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Fri, 17 Jan 2025 11:49:35 +0100
Subject: [PATCH] [clang][bytecode] Add InitLinkScope for toplevel Expr
temporary
---
clang/lib/AST/ByteCode/Compiler.cpp | 1 +
clang/test/AST/ByteCode/cxx20.cpp | 15 +++++++++++++++
2 files changed, 16 insertions(+)
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index 4bfb80589620c1..6677119d092119 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -4247,6 +4247,7 @@ bool Compiler<Emitter>::visitExpr(const Expr *E, bool DestroyToplevelScope) {
// For us, that means everything we don't
// have a PrimType for.
if (std::optional<unsigned> LocalOffset = this->allocateLocal(E)) {
+ InitLinkScope<Emitter> ILS(this, InitLink::Temp(*LocalOffset));
if (!this->emitGetPtrLocal(*LocalOffset, E))
return false;
diff --git a/clang/test/AST/ByteCode/cxx20.cpp b/clang/test/AST/ByteCode/cxx20.cpp
index 268362ceff635b..268226a7c143ed 100644
--- a/clang/test/AST/ByteCode/cxx20.cpp
+++ b/clang/test/AST/ByteCode/cxx20.cpp
@@ -893,3 +893,18 @@ namespace VirtDtor {
static_assert(test('C', 'B'));
}
+
+namespace TemporaryInNTTP {
+ template<auto n> struct B { /* ... */ };
+ struct J1 {
+ J1 *self=this;
+ };
+ /// FIXME: The bytecode interpreter emits a different diagnostic here.
+ /// The current interpreter creates a fake MaterializeTemporaryExpr (see EvaluateAsConstantExpr)
+ /// which is later used as the LValueBase of the created APValue.
+ B<J1{}> j1; // ref-error {{pointer to temporary object is not allowed in a template argument}} \
+ // expected-error {{non-type template argument is not a constant expression}} \
+ // expected-note {{pointer to temporary is not a constant expression}} \
+ // expected-note {{created here}}
+ B<2> j2; /// Ok.
+}
More information about the cfe-commits
mailing list