This is an archive of the discontinued LLVM Phabricator instance.

Mark derived destructors as `override`
ClosedPublic

Authored by antoniofrighetto on Mar 18 2022, 4:33 AM.

Details

Summary

Derived destructors can be marked as override, in order to prevent possible compilation failures of projects depending on those headers (when compiled with flags -Wall, -Wsuggest-destructor-override, -Winconsistent-missing-destructor-override).

Diff Detail

Event Timeline

Herald added a project: Restricted Project. · View Herald TranscriptMar 18 2022, 4:33 AM
antoniofrighetto requested review of this revision.Mar 18 2022, 4:33 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 18 2022, 4:33 AM
dblaikie added inline comments.Mar 18 2022, 9:10 AM
llvm/include/llvm/Analysis/ScalarEvolution.h
227 ↗(On Diff #416460)

Why is this being made virtual?

llvm/include/llvm/IR/IRBuilder.h
80

Please drop virtual when adding override.

llvm/include/llvm/Analysis/ScalarEvolution.h
227 ↗(On Diff #416460)

Might be wrong, but, considering that SCEVPredicate is being inherited, the order of destruction object should be carried out correctly, when a derived object goes out of scope (even if no instance of the derived object is reachable through a pointer to the base class) . That actually should be added at every level of the hirearchy.

dblaikie added inline comments.Mar 18 2022, 10:27 AM
llvm/include/llvm/Analysis/ScalarEvolution.h
227 ↗(On Diff #416460)

If the type isn't owned/destroyed dynamically, then it isn't necessary to make the dtor virtual - that's why the dtor's protected, so it can't be destroyed dynamically.

eg, this code is OK:

struct base {
  virtual void f();
protected:
  ~base();
};
struct derived final : base {
  void f();
};
void f(base *b) {
  b->f();
}
...
derived d;
f(&d);

The destruction is non-polymorphic/non-dynamic even though the usage may be dynamic.

This class is designed to work in this way & Clang's warnings have been implemented to allow this usage & avoiding dynamic dispatch overhead where it isn't needed.

antoniofrighetto edited the summary of this revision. (Show Details)

@dblaikie: That's true, admittedly, had not noticed the protected dtor (which works as well). Fixed it up, thanks for contextualizing.

llvm/include/llvm/Analysis/ScalarEvolution.h
227 ↗(On Diff #416460)

That's true, admittedly, I didn't notice the protected dtor.

antoniofrighetto marked an inline comment as done.Mar 18 2022, 1:29 PM

Looks great, thanks!

nikic accepted this revision.Mar 24 2022, 3:41 AM
This revision is now accepted and ready to land.Mar 24 2022, 3:41 AM
This revision was automatically updated to reflect the committed changes.