[clang] [clang][bytecode] Add a variable scope for virtual base initializers (PR #237933)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 2 04:00:39 PST 2026
https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/237933
Otherwise we have no scope to attach temporary variables created as part of the virtual base initializer to.
>From c7b2020018e237288dbb5ce738d58968a9606f34 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Mon, 2 Nov 2026 12:47:21 +0100
Subject: [PATCH] [clang][bytecode] Add a variable scope for virtual base
initializers
Otherwise we have no scope to attach temporary variables created as part
of the virtual base initializer to.
---
clang/lib/AST/ByteCode/Compiler.cpp | 1 +
clang/test/AST/ByteCode/virtual-bases.cpp | 9 +++++++++
2 files changed, 10 insertions(+)
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index 71f761f58aed28..dc59a12bbde811 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -7759,6 +7759,7 @@ bool Compiler<Emitter>::compileConstructor(const CXXConstructorDecl *Ctor) {
return false;
for (const auto *Init : Ctor->inits()) {
+ LocalScope<Emitter> VirtLocalScope(this);
if (const Type *Base = Init->getBaseClass();
Base && Init->isBaseVirtual()) {
const auto *BaseDecl = Base->getAsCXXRecordDecl();
diff --git a/clang/test/AST/ByteCode/virtual-bases.cpp b/clang/test/AST/ByteCode/virtual-bases.cpp
index f8dabd43749a50..47e8bbd6a2daf8 100644
--- a/clang/test/AST/ByteCode/virtual-bases.cpp
+++ b/clang/test/AST/ByteCode/virtual-bases.cpp
@@ -486,3 +486,12 @@ namespace MostDerivedIsArrayElem {
static_assert(d[8].n == 7);
static_assert(d[8].k == 0);
}
+
+namespace TemoprariesInVirtualBaseInitializer {
+ struct S {};
+ struct C {
+ C(C &, S s = S());
+ };
+ struct D : virtual C {};
+ void foo(D d) { D d2(d); };
+}
More information about the cfe-commits
mailing list