public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [pushed] Add virtual destructor to selftest
@ 2017-12-07 16:50 Simon Marchi
  0 siblings, 0 replies; only message in thread
From: Simon Marchi @ 2017-12-07 16:50 UTC (permalink / raw)
  To: gdb-patches; +Cc: Simon Marchi

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.
---
 gdb/ChangeLog         | 4 ++++
 gdb/common/selftest.h | 1 +
 2 files changed, 5 insertions(+)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index 9ba0254..54aec7f 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,3 +1,7 @@
+2017-12-07  Simon Marchi  <simon.marchi@ericsson.com>
+
+	* common/selftest.h (struct selftest): Add virtual destructor.
+
 2017-12-07  Phil Muldoon  <pmuldoon@redhat.com>
 
 	* python/py-breakpoint.c (bppy_init): Use string_to_event_location
diff --git a/gdb/common/selftest.h b/gdb/common/selftest.h
index 35a344f..7e91bd4 100644
--- a/gdb/common/selftest.h
+++ b/gdb/common/selftest.h
@@ -31,6 +31,7 @@ namespace selftests
 
 struct selftest
 {
+  virtual ~selftest () = default;
   virtual void operator() () const = 0;
 };
 
-- 
2.7.4

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2017-12-07 16:50 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-12-07 16:50 [pushed] Add virtual destructor to selftest Simon Marchi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).