[llvm-bugs] [Bug 25850] New: non-virtual destructor not detected with friend

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Dec 16 02:35:26 PST 2015


            Bug ID: 25850
           Summary: non-virtual destructor not detected with friend
           Product: clang
           Version: trunk
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++
          Assignee: unassignedclangbugs at nondot.org
          Reporter: andyg1001 at hotmail.co.uk
                CC: dgregor at apple.com, llvm-bugs at lists.llvm.org
    Classification: Unclassified

The following code compiles "fine" with clang, but should really (in my
opinion) produce an error inside other::test() that the code is calling a
non-virtual destructor.

class base {
  friend struct other;
  public: virtual void fn();
  protected: ~base();

class derived final : public base {
  public: ~derived();
  int data;

struct other {
  void test() {
    base* b = new derived();
    delete b;

GCC produces a warning which is arguably too pro-active since it produces it
immediately on the declaration of derived.  However, I feel it would be
advantageous/correct to trap the error at the point of use inside

Side note: This bug report comes out of a recent discussion with David Blaikie
over LLVM commit r254592.  That commit changed the base dtor to virtual to
silence the gcc warning.  Note, of course, that there isn't an equivalent of
other::test() in the LLVM codebase (currently!) but I would feel happier about
rolling-back the commit to the non-virtual base dtor (and silence the gcc
warning) if I felt clang would correctly detect this corner case.

Is this reasonable?

You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20151216/29ddcee5/attachment.html>

More information about the llvm-bugs mailing list