File tree Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change @@ -858,3 +858,47 @@ namespace DefinitionLoc {
858
858
constexpr NonConstexprCopy ncc2 = ncc1; // both-error {{constant expression}} \
859
859
// both-note {{non-constexpr constructor}}
860
860
}
861
+
862
+ // / FIXME: Call base dtors when explicitly calling dtor.
863
+ namespace VirtDtor {
864
+ class B {
865
+ public:
866
+ constexpr B (char *p) : p(p) {}
867
+ virtual constexpr ~B () {
868
+ *p = ' B' ;
869
+ ++p;
870
+ }
871
+
872
+ char *p;
873
+ };
874
+
875
+ class C : public B {
876
+ public:
877
+ constexpr C (char *p) : B(p) {}
878
+ virtual constexpr ~C () override {
879
+ *p = ' C' ;
880
+ ++p;
881
+ }
882
+ };
883
+
884
+ union U {
885
+ constexpr U (char *p) : c (p) {}
886
+ constexpr ~U () {}
887
+
888
+ C c;
889
+ };
890
+
891
+ constexpr int test (char a, char b) {
892
+ char buff[2 ] = {};
893
+ U u (buff);
894
+
895
+ // / U is a union, so it won't call the destructor of its fields.
896
+ // / We do this manually here. Explicitly calling ~C() here should
897
+ // / also call the destructor of the base classes however.
898
+ u.c .~C ();
899
+
900
+ return buff[0 ] == a && buff[1 ] == b;
901
+ }
902
+
903
+ static_assert (test(' C' , ' B' )); // expected-error {{failed}}
904
+ }
You can’t perform that action at this time.
0 commit comments