Skip to content

Commit

Permalink
Add -Wnon-virtual-dtor and virtual destructors
Browse files Browse the repository at this point in the history
This warning detects classes with virtual functions but a non-virtual
destructor.  Deleting instances through pointers whose type is such a
class is undefined behaviour.

I'm not certain whether any of the classes I've added the virtual
destructors to here actually needed it, but there should be negligible
performance impact, and it's a good warning to have enabled.
  • Loading branch information
jbytheway committed Feb 22, 2020
1 parent 054b3e6 commit 79b5ab7
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ ELSE()
-Wlogical-op \
-Wmissing-declarations \
-Wmissing-noreturn \
-Wnon-virtual-dtor \
-Wold-style-cast \
-Woverloaded-virtual \
-Wpedantic \
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ WARNINGS = \
-Wlogical-op \
-Wmissing-declarations \
-Wmissing-noreturn \
-Wnon-virtual-dtor \
-Wold-style-cast \
-Woverloaded-virtual \
-Wpedantic \
Expand Down
1 change: 1 addition & 0 deletions src/behavior_strategy.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ struct behavior_return;
class strategy_t
{
public:
virtual ~strategy_t() = default;
virtual behavior_return evaluate( const oracle_t *subject,
std::vector<const node_t *> children ) const = 0;
};
Expand Down
3 changes: 2 additions & 1 deletion src/inventory_ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ class inventory_selector_preset
{
public:
inventory_selector_preset();
virtual ~inventory_selector_preset() = default;

/** Does this entry satisfy the basic preset conditions? */
virtual bool is_shown( const item_location & ) const {
Expand Down Expand Up @@ -424,7 +425,7 @@ class inventory_selector
{
public:
inventory_selector( player &u, const inventory_selector_preset &preset = default_preset );
~inventory_selector();
virtual ~inventory_selector();
/** These functions add items from map / vehicles. */
void add_character_items( Character &character );
void add_map_items( const tripoint &target );
Expand Down
1 change: 1 addition & 0 deletions src/item_stack.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class item_stack
using const_reverse_iterator = cata::colony<item>::const_reverse_iterator;

item_stack( cata::colony<item> *items ) : items( items ) { }
virtual ~item_stack() = default;

size_t size() const;
bool empty() const;
Expand Down

0 comments on commit 79b5ab7

Please sign in to comment.