[clang] 2a00bf4 - [clang][Interp][NFC] Add a failing test case (#102801)

via cfe-commits cfe-commits at lists.llvm.org
Sun Aug 11 01:18:05 PDT 2024


Author: Timm Baeder
Date: 2024-08-11T10:18:01+02:00
New Revision: 2a00bf412efec1f87fed0762ee42dd7a6b809cbb

URL: https://github.com/llvm/llvm-project/commit/2a00bf412efec1f87fed0762ee42dd7a6b809cbb
DIFF: https://github.com/llvm/llvm-project/commit/2a00bf412efec1f87fed0762ee42dd7a6b809cbb.diff

LOG: [clang][Interp][NFC] Add a failing test case (#102801)

Added: 
    

Modified: 
    clang/test/AST/Interp/cxx20.cpp

Removed: 
    


################################################################################
diff  --git a/clang/test/AST/Interp/cxx20.cpp b/clang/test/AST/Interp/cxx20.cpp
index 27dbd2818be60..389d9d883725f 100644
--- a/clang/test/AST/Interp/cxx20.cpp
+++ b/clang/test/AST/Interp/cxx20.cpp
@@ -858,3 +858,47 @@ namespace DefinitionLoc {
   constexpr NonConstexprCopy ncc2 = ncc1; // both-error {{constant expression}} \
                                           // both-note {{non-constexpr constructor}}
 }
+
+/// FIXME: Call base dtors when explicitly calling dtor.
+namespace VirtDtor {
+  class B {
+  public:
+    constexpr B(char *p) : p(p) {}
+    virtual constexpr ~B() {
+      *p = 'B';
+      ++p;
+    }
+
+    char *p;
+  };
+
+  class C : public B {
+  public:
+    constexpr C(char *p) : B(p) {}
+    virtual constexpr ~C() override {
+      *p = 'C';
+      ++p;
+    }
+  };
+
+  union U {
+    constexpr U(char *p) : c(p) {}
+    constexpr ~U() {}
+
+    C c;
+  };
+
+  constexpr int test(char a, char b) {
+    char buff[2] = {};
+    U u(buff);
+
+    /// U is a union, so it won't call the destructor of its fields.
+    /// We do this manually here. Explicitly calling ~C() here should
+    /// also call the destructor of the base classes however.
+    u.c.~C();
+
+    return buff[0] == a && buff[1] == b;
+  }
+
+  static_assert(test('C', 'B')); // expected-error {{failed}}
+}


        


More information about the cfe-commits mailing list