Skip to content

Wdelete-non-virtual-dtor doesn't work with std::unique_ptr #28834

@nico

Description

@nico
Bugzilla Link 28460
Resolution FIXED
Resolved on Sep 02, 2017 12:47
Version unspecified
OS Linux
CC @zetafunction,@DougGregor

Extended Description

This warns, like it should:

thakis@thakis:~/src/chrome/src$ cat test.cc
#include <memory>

struct S {
  virtual void f() {}
};

struct T : public S {
};

void f(S* s) {
  delete s;
}
thakis@thakis:~/src/chrome/src$ third_party/llvm-build/Release+Asserts/bin/clang -c test.cc -Wall -std=c++11 
test.cc:11:3: warning: delete called on non-final 'S' that has virtual functions but non-virtual destructor [-Wdelete-non-virtual-dtor]
  delete s;
  ^
1 warning generated.

But this doesn't:

thakis@thakis:~/src/chrome/src$ cat test.cc
#include <memory>

struct S {
  virtual void f() {}
};

struct T : public S {
};

void f() {
  std::unique_ptr<S> s;
}
thakis@thakis:~/src/chrome/src$ third_party/llvm-build/Release+Asserts/bin/clang -c test.cc -Wall -std=c++11 

It should.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugzillaIssues migrated from bugzillac++

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions