Commit e338d636 authored by Kenton Varda's avatar Kenton Varda

Fix GCC harder: Only instantiate final types, I guess.

parent ec59b987
...@@ -136,12 +136,6 @@ TEST(Memory, AttachNested) { ...@@ -136,12 +136,6 @@ TEST(Memory, AttachNested) {
KJ_EXPECT(destroyed3 == 3, destroyed3); KJ_EXPECT(destroyed3 == 3, destroyed3);
} }
#if __GNUG__
// We don't actually illegally invoke any non-virtual destructors but it's hard to write this test
// without triggering this warning, so ignore it.
#pragma GCC diagnostic ignored "-Wdelete-non-virtual-dtor"
#endif
struct StaticType { struct StaticType {
int i; int i;
}; };
...@@ -162,15 +156,27 @@ struct DynamicType2 { ...@@ -162,15 +156,27 @@ struct DynamicType2 {
DynamicType2(int k): k(k) {} DynamicType2(int k): k(k) {}
}; };
struct DerivedDynamic: public DynamicType1, public DynamicType2 { struct SingularDerivedDynamic final: public DynamicType1 {
DerivedDynamic(int j, int k, bool& destructorCalled) SingularDerivedDynamic(int j, bool& destructorCalled)
: DynamicType1(j), destructorCalled(destructorCalled) {}
~SingularDerivedDynamic() {
destructorCalled = true;
}
KJ_DISALLOW_COPY(SingularDerivedDynamic);
bool& destructorCalled;
};
struct MultipleDerivedDynamic final: public DynamicType1, public DynamicType2 {
MultipleDerivedDynamic(int j, int k, bool& destructorCalled)
: DynamicType1(j), DynamicType2(k), destructorCalled(destructorCalled) {} : DynamicType1(j), DynamicType2(k), destructorCalled(destructorCalled) {}
~DerivedDynamic() { ~MultipleDerivedDynamic() {
destructorCalled = true; destructorCalled = true;
} }
KJ_DISALLOW_COPY(DerivedDynamic); KJ_DISALLOW_COPY(MultipleDerivedDynamic);
bool& destructorCalled; bool& destructorCalled;
}; };
...@@ -184,16 +190,17 @@ TEST(Memory, OwnVoid) { ...@@ -184,16 +190,17 @@ TEST(Memory, OwnVoid) {
} }
{ {
Own<DynamicType1> ptr = heap<DynamicType1>(123); bool destructorCalled = false;
DynamicType1* addr = ptr.get(); Own<SingularDerivedDynamic> ptr = heap<SingularDerivedDynamic>(123, destructorCalled);
SingularDerivedDynamic* addr = ptr.get();
Own<void> voidPtr = kj::mv(ptr); Own<void> voidPtr = kj::mv(ptr);
KJ_EXPECT(voidPtr.get() == implicitCast<void*>(addr)); KJ_EXPECT(voidPtr.get() == implicitCast<void*>(addr));
} }
{ {
bool destructorCalled = false; bool destructorCalled = false;
Own<DerivedDynamic> ptr = heap<DerivedDynamic>(123, 456, destructorCalled); Own<MultipleDerivedDynamic> ptr = heap<MultipleDerivedDynamic>(123, 456, destructorCalled);
DerivedDynamic* addr = ptr.get(); MultipleDerivedDynamic* addr = ptr.get();
Own<void> voidPtr = kj::mv(ptr); Own<void> voidPtr = kj::mv(ptr);
KJ_EXPECT(voidPtr.get() == implicitCast<void*>(addr)); KJ_EXPECT(voidPtr.get() == implicitCast<void*>(addr));
...@@ -204,8 +211,8 @@ TEST(Memory, OwnVoid) { ...@@ -204,8 +211,8 @@ TEST(Memory, OwnVoid) {
{ {
bool destructorCalled = false; bool destructorCalled = false;
Own<DerivedDynamic> ptr = heap<DerivedDynamic>(123, 456, destructorCalled); Own<MultipleDerivedDynamic> ptr = heap<MultipleDerivedDynamic>(123, 456, destructorCalled);
DerivedDynamic* addr = ptr.get(); MultipleDerivedDynamic* addr = ptr.get();
Own<DynamicType2> basePtr = kj::mv(ptr); Own<DynamicType2> basePtr = kj::mv(ptr);
DynamicType2* baseAddr = basePtr.get(); DynamicType2* baseAddr = basePtr.get();
...@@ -237,16 +244,17 @@ TEST(Memory, OwnConstVoid) { ...@@ -237,16 +244,17 @@ TEST(Memory, OwnConstVoid) {
} }
{ {
Own<DynamicType1> ptr = heap<DynamicType1>(123); bool destructorCalled = false;
DynamicType1* addr = ptr.get(); Own<SingularDerivedDynamic> ptr = heap<SingularDerivedDynamic>(123, destructorCalled);
SingularDerivedDynamic* addr = ptr.get();
Own<const void> voidPtr = kj::mv(ptr); Own<const void> voidPtr = kj::mv(ptr);
KJ_EXPECT(voidPtr.get() == implicitCast<void*>(addr)); KJ_EXPECT(voidPtr.get() == implicitCast<void*>(addr));
} }
{ {
bool destructorCalled = false; bool destructorCalled = false;
Own<DerivedDynamic> ptr = heap<DerivedDynamic>(123, 456, destructorCalled); Own<MultipleDerivedDynamic> ptr = heap<MultipleDerivedDynamic>(123, 456, destructorCalled);
DerivedDynamic* addr = ptr.get(); MultipleDerivedDynamic* addr = ptr.get();
Own<const void> voidPtr = kj::mv(ptr); Own<const void> voidPtr = kj::mv(ptr);
KJ_EXPECT(voidPtr.get() == implicitCast<void*>(addr)); KJ_EXPECT(voidPtr.get() == implicitCast<void*>(addr));
...@@ -257,8 +265,8 @@ TEST(Memory, OwnConstVoid) { ...@@ -257,8 +265,8 @@ TEST(Memory, OwnConstVoid) {
{ {
bool destructorCalled = false; bool destructorCalled = false;
Own<DerivedDynamic> ptr = heap<DerivedDynamic>(123, 456, destructorCalled); Own<MultipleDerivedDynamic> ptr = heap<MultipleDerivedDynamic>(123, 456, destructorCalled);
DerivedDynamic* addr = ptr.get(); MultipleDerivedDynamic* addr = ptr.get();
Own<DynamicType2> basePtr = kj::mv(ptr); Own<DynamicType2> basePtr = kj::mv(ptr);
DynamicType2* baseAddr = basePtr.get(); DynamicType2* baseAddr = basePtr.get();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment