Author: Timm Baeder
Date: 2026-11-02T13:48:36+01:00
New Revision: 9bfa2c2d313a6d0b530d43ccd429ff71afd7b979

URL: 
https://github.com/llvm/llvm-project/commit/9bfa2c2d313a6d0b530d43ccd429ff71afd7b979
DIFF: 
https://github.com/llvm/llvm-project/commit/9bfa2c2d313a6d0b530d43ccd429ff71afd7b979.diff

LOG: [clang][bytecode] Add a variable scope for virtual base initializers 
(#237933)

Otherwise we have no scope to attach temporary variables created as part
of the virtual base initializer to.

Added: 
    

Modified: 
    clang/lib/AST/ByteCode/Compiler.cpp
    clang/test/AST/ByteCode/virtual-bases.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/ByteCode/Compiler.cpp 
b/clang/lib/AST/ByteCode/Compiler.cpp
index 71f761f58aed2..dc59a12bbde81 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 f8dabd43749a5..47e8bbd6a2daf 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); };
+}


        
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to