[clang] [clang-repl] fix vtable symbol duplication error (closes #141039) (PR #185648)

Emery Conrad via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 1 06:29:33 PDT 2026


================
@@ -0,0 +1,40 @@
+// REQUIRES: host-supports-jit
+// RUN: cat %s | clang-repl | FileCheck %s
+// virtual functions defined outside of class had duplicate symbols:
+//     duplicate definition of symbol '__ZTV3Two' (i.e., vtable for Two)
+// see https://github.com/llvm/llvm-project/issues/141039.
+// fixed in PR #185648
+
+extern "C" int printf(const char *, ...);
+
+struct X1 { virtual void vi() { printf("1vi\n"); } };
+X1().vi();
+// CHECK: 1vi
+
+struct X2 { virtual void vo(); };
+void X2::vo() { printf("2vo\n"); }
+X2().vo();
+// CHECK: 2vo
+
+struct X3 { \
+  void ni() { printf("3ni\n"); } \
+  void no(); \
+  virtual void vi() { printf("3vi\n"); } \
+  virtual void vo(); \
+  virtual ~X3() { printf("3d\n"); } \
+};
+void X3::no() { printf("3no\n"); }
+void X3::vo() { printf("3vo\n"); }
+auto x3 = new X3;
+x3->ni();
+// CHECK: 3ni
+x3->no();
+// CHECK: 3no
+x3->vi();
+// CHECK: 3vi
+x3->vo();
+// CHECK: 3vo
+delete x3;
+// CHECK: 3d
+
+%quit
----------------
conrade-ctc wrote:

Actually, @anutosh491, I presume that the jupyter setup treats each cell as single string input to cppyy.cppdef, which would be a single PTU per cell, so you need to actually split each line from the test into a separate cell to see the bug I think.

https://github.com/llvm/llvm-project/pull/185648


More information about the cfe-commits mailing list