Everything: Add -Wnon-virtual-dtor flag

This flag warns on classes which have `virtual` functions but do not
have a `virtual` destructor.

This patch adds both the flag and missing destructors. The access level
of the destructors was determined by a two rules of thumb:
1. A destructor should have a similar or lower access level to that of a
   constructor.
2. Having a `private` destructor implicitly deletes the default
   constructor, which is probably undesirable for "interface" types
   (classes with only virtual functions and no data).

In short, most of the added destructors are `protected`, unless the
compiler complained about access.
This commit is contained in:
Nicholas-Baron 2021-04-15 10:43:29 -07:00 committed by Andreas Kling
parent b75d2d36e1
commit c4ede38542
Notes: sideshowbarker 2024-07-18 20:17:38 +09:00
21 changed files with 57 additions and 0 deletions

View file

@ -174,6 +174,7 @@ add_compile_options(-Wlogical-op)
add_compile_options(-Wmisleading-indentation) add_compile_options(-Wmisleading-indentation)
add_compile_options(-Wmissing-declarations) add_compile_options(-Wmissing-declarations)
add_compile_options(-Wno-nonnull-compare) add_compile_options(-Wno-nonnull-compare)
add_compile_options(-Wnon-virtual-dtor)
add_compile_options(-Wno-unknown-warning-option) add_compile_options(-Wno-unknown-warning-option)
add_compile_options(-Wundef) add_compile_options(-Wundef)
add_compile_options(-Wunused) add_compile_options(-Wunused)

View file

@ -69,6 +69,7 @@ public:
protected: protected:
explicit Parser(PhysicalAddress rsdp); explicit Parser(PhysicalAddress rsdp);
virtual ~Parser() = default;
private: private:
static void set_the(Parser&); static void set_the(Parser&);

View file

@ -83,6 +83,9 @@ public:
void enumerate_interrupt_handlers(Function<void(GenericInterruptHandler&)>); void enumerate_interrupt_handlers(Function<void(GenericInterruptHandler&)>);
IRQController& get_interrupt_controller(int index); IRQController& get_interrupt_controller(int index);
protected:
virtual ~InterruptManagement() = default;
private: private:
InterruptManagement(); InterruptManagement();
PhysicalAddress search_for_madt(); PhysicalAddress search_for_madt();

View file

@ -66,6 +66,8 @@ protected:
u16 early_read_type(Address address); u16 early_read_type(Address address);
Access(); Access();
virtual ~Access() = default;
Vector<PhysicalID> m_physical_ids; Vector<PhysicalID> m_physical_ids;
}; };

View file

@ -49,6 +49,9 @@ public:
virtual void image_did_modify_layer_stack() { } virtual void image_did_modify_layer_stack() { }
virtual void image_did_change() { } virtual void image_did_change() { }
virtual void image_select_layer(Layer*) { } virtual void image_select_layer(Layer*) { }
protected:
virtual ~ImageClient() = default;
}; };
class Image : public RefCounted<Image> { class Image : public RefCounted<Image> {

View file

@ -84,6 +84,8 @@ public:
PlaybackManager& manager() { return m_player_state.manager; } PlaybackManager& manager() { return m_player_state.manager; }
protected: protected:
virtual ~Player() = default;
PlayerState m_player_state; PlayerState m_player_state;
RefPtr<PlaylistModel> m_playlist_model; RefPtr<PlaylistModel> m_playlist_model;
}; };

View file

@ -32,4 +32,7 @@ class Visualization {
public: public:
virtual void set_buffer(RefPtr<Audio::Buffer> buffer) = 0; virtual void set_buffer(RefPtr<Audio::Buffer> buffer) = 0;
virtual void set_samplerate(int) { } virtual void set_samplerate(int) { }
protected:
virtual ~Visualization() = default;
}; };

View file

@ -37,6 +37,9 @@ struct TreeMapNode {
virtual size_t num_children() const = 0; virtual size_t num_children() const = 0;
virtual const TreeMapNode& child_at(size_t i) const = 0; virtual const TreeMapNode& child_at(size_t i) const = 0;
virtual void sort_children_by_area() const = 0; virtual void sort_children_by_area() const = 0;
protected:
virtual ~TreeMapNode() = default;
}; };
struct TreeMap : public RefCounted<TreeMap> { struct TreeMap : public RefCounted<TreeMap> {

View file

@ -35,6 +35,9 @@ class ChecksumFunction {
public: public:
virtual void update(ReadonlyBytes data) = 0; virtual void update(ReadonlyBytes data) = 0;
virtual ChecksumType digest() = 0; virtual ChecksumType digest() = 0;
protected:
virtual ~ChecksumFunction() = default;
}; };
} }

View file

@ -92,6 +92,9 @@ public:
ptr[index] = (u8)value; ptr[index] = (u8)value;
} }
protected:
virtual ~CipherBlock() = default;
private: private:
virtual Bytes bytes() = 0; virtual Bytes bytes() = 0;
PaddingMode m_padding_mode; PaddingMode m_padding_mode;
@ -132,6 +135,9 @@ public:
virtual String class_name() const = 0; virtual String class_name() const = 0;
protected:
virtual ~Cipher() = default;
private: private:
PaddingMode m_padding_mode; PaddingMode m_padding_mode;
}; };

View file

@ -57,6 +57,9 @@ public:
virtual void reset() = 0; virtual void reset() = 0;
virtual String class_name() const = 0; virtual String class_name() const = 0;
protected:
virtual ~HashFunction() = default;
}; };
} }
} }

View file

@ -48,6 +48,8 @@ public:
HashFunction& hasher() { return m_hasher; } HashFunction& hasher() { return m_hasher; }
protected: protected:
virtual ~Code() = default;
HashFunction m_hasher; HashFunction m_hasher;
}; };

View file

@ -60,6 +60,8 @@ public:
virtual size_t output_size() const = 0; virtual size_t output_size() const = 0;
protected: protected:
virtual ~PKSystem() = default;
PublicKeyType m_public_key; PublicKeyType m_public_key;
PrivateKeyType m_private_key; PrivateKeyType m_private_key;
}; };

View file

@ -93,6 +93,8 @@ public:
virtual Value count_reset() = 0; virtual Value count_reset() = 0;
protected: protected:
virtual ~ConsoleClient() = default;
VM& vm(); VM& vm();
GlobalObject& global_object() { return m_console.global_object(); } GlobalObject& global_object() { return m_console.global_object(); }

View file

@ -58,6 +58,7 @@ public:
protected: protected:
virtual void visit_impl(Cell*) = 0; virtual void visit_impl(Cell*) = 0;
virtual ~Visitor() = default;
}; };
virtual void visit_edges(Visitor&) { } virtual void visit_edges(Visitor&) { }

View file

@ -33,6 +33,9 @@ namespace TextCodec {
class Decoder { class Decoder {
public: public:
virtual String to_utf8(const StringView&) = 0; virtual String to_utf8(const StringView&) = 0;
protected:
virtual ~Decoder() = default;
}; };
class UTF8Decoder final : public Decoder { class UTF8Decoder final : public Decoder {

View file

@ -113,6 +113,9 @@ public:
virtual String page_did_request_prompt(const String&, const String&) { return {}; } virtual String page_did_request_prompt(const String&, const String&) { return {}; }
virtual String page_did_request_cookie(const URL&, Cookie::Source) { return {}; } virtual String page_did_request_cookie(const URL&, Cookie::Source) { return {}; }
virtual void page_did_set_cookie(const URL&, const String&, Cookie::Source) { } virtual void page_did_set_cookie(const URL&, const String&, Cookie::Source) { }
protected:
virtual ~PageClient() = default;
}; };
} }

View file

@ -41,6 +41,9 @@ typedef void (Interpreter::*InstructionHandler)(const Instruction&);
class SymbolProvider { class SymbolProvider {
public: public:
virtual String symbolicate(FlatPtr, u32* offset = nullptr) const = 0; virtual String symbolicate(FlatPtr, u32* offset = nullptr) const = 0;
protected:
virtual ~SymbolProvider() = default;
}; };
template<typename T> template<typename T>
@ -316,6 +319,9 @@ public:
virtual u16 read16() = 0; virtual u16 read16() = 0;
virtual u32 read32() = 0; virtual u32 read32() = 0;
virtual u64 read64() = 0; virtual u64 read64() = 0;
protected:
virtual ~InstructionStream() = default;
}; };
class SimpleInstructionStream final : public InstructionStream { class SimpleInstructionStream final : public InstructionStream {

View file

@ -622,6 +622,9 @@ public:
virtual void wrap_0xD2(const Instruction&) = 0; virtual void wrap_0xD2(const Instruction&) = 0;
virtual void wrap_0xD3_16(const Instruction&) = 0; virtual void wrap_0xD3_16(const Instruction&) = 0;
virtual void wrap_0xD3_32(const Instruction&) = 0; virtual void wrap_0xD3_32(const Instruction&) = 0;
protected:
virtual ~Interpreter() = default;
}; };
typedef void (Interpreter::*InstructionHandler)(const Instruction&); typedef void (Interpreter::*InstructionHandler)(const Instruction&);

View file

@ -75,6 +75,9 @@ public:
virtual void visit(const AST::VariableDeclarations*); virtual void visit(const AST::VariableDeclarations*);
virtual void visit(const AST::WriteAppendRedirection*); virtual void visit(const AST::WriteAppendRedirection*);
virtual void visit(const AST::WriteRedirection*); virtual void visit(const AST::WriteRedirection*);
protected:
virtual ~NodeVisitor() = default;
}; };
} }

View file

@ -99,6 +99,8 @@ public:
s_the = this; s_the = this;
} }
virtual ~TestRunner() = default;
void run(); void run();
const Test::Counts& counts() const { return m_counts; } const Test::Counts& counts() const { return m_counts; }