Skip to content

Commit 30970df

Browse files
author
Simon Marchi
committed
Add virtual destructor to selftest
Clang 6 shows this warning In file included from /home/emaisin/src/binutils-gdb/gdb/common/selftest.c:19: In file included from /home/emaisin/src/binutils-gdb/gdb/common/common-defs.h:92: In file included from /home/emaisin/src/binutils-gdb/gdb/common/gdb_unique_ptr.h:23: In file included from /usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../../../include/c++/5.4.0/memory:81: /usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../../../include/c++/5.4.0/bits/unique_ptr.h:76:2: error: delete called on 'selftests::selftest' that is abstract but has non-virtual destructor [-Werror,-Wdelete-non-virtual-dtor] delete __ptr; ^ /usr/bin/../lib/gcc/x86_64-linux-gnu/5.4.0/../../../../include/c++/5.4.0/bits/unique_ptr.h:236:4: note: in instantiation of member function 'std::default_delete<selftests::selftest>::operator()' requested here get_deleter()(__ptr); ^ /home/emaisin/src/binutils-gdb/gdb/common/selftest.c:57:17: note: in instantiation of member function 'std::unique_ptr<selftests::selftest, std::default_delete<selftests::selftest> >::~unique_ptr' requested here tests[name] = std::unique_ptr<selftest> (test); ^ The error is legitimate, we (the unique_ptr) are deleting selftest objects through the base pointer, so technically the destructor should be virtual, so that the destructor of the subclass is invoked. gdb/ChangeLog: * common/selftest.h (struct selftest): Add virtual destructor.
1 parent 824cc83 commit 30970df

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

gdb/ChangeLog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
2017-12-07 Simon Marchi <simon.marchi@ericsson.com>
2+
3+
* common/selftest.h (struct selftest): Add virtual destructor.
4+
15
2017-12-07 Phil Muldoon <pmuldoon@redhat.com>
26

37
* python/py-breakpoint.c (bppy_init): Use string_to_event_location

gdb/common/selftest.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ namespace selftests
3131

3232
struct selftest
3333
{
34+
virtual ~selftest () = default;
3435
virtual void operator() () const = 0;
3536
};
3637

0 commit comments

Comments
 (0)