Add virtual destructor to selftest
authorSimon Marchi <simon.marchi@ericsson.com>
Thu, 7 Dec 2017 16:48:21 +0000 (11:48 -0500)
committerSimon Marchi <simon.marchi@ericsson.com>
Thu, 7 Dec 2017 16:49:01 +0000 (11:49 -0500)
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
gdb/common/selftest.h

index 9ba02541617fc58837f6da33b0b45e4ce4115975..54aec7f7d9e43360469bb8a8873a1f0d1f1ec411 100644 (file)
@@ -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
index 35a344ff6cff8860485fc58d19473b5be33479c7..7e91bd41bfec334f9556c0485a760ffd706358de 100644 (file)
@@ -31,6 +31,7 @@ namespace selftests
 
 struct selftest
 {
+  virtual ~selftest () = default;
   virtual void operator() () const = 0;
 };