diff --git a/llvm/include/llvm/Analysis/DOTGraphTraitsPass.h b/llvm/include/llvm/Analysis/DOTGraphTraitsPass.h --- a/llvm/include/llvm/Analysis/DOTGraphTraitsPass.h +++ b/llvm/include/llvm/Analysis/DOTGraphTraitsPass.h @@ -44,7 +44,6 @@ : PassInfoMixin> { DOTGraphTraitsViewer(StringRef GraphName) : Name(GraphName) {} - virtual ~DOTGraphTraitsViewer() {} /// Return true if this function should be processed. /// @@ -68,6 +67,18 @@ return PreservedAnalyses::all(); }; +protected: + /// Avoid compiler warning "has virtual functions but non-virtual destructor + /// [-Wnon-virtual-dtor]" in derived classes. + /// + /// DOTGraphTraitsViewer is also used as a mixin for avoiding repeated + /// implementation of viewer passes, ie there should be no + /// runtime-polymorphisms/downcasting involving this class and hence no + /// virtual destructor needed. Making this dtor protected stops accidental + /// invocation when the derived class destructor should have been called. + /// Those derived classes sould be marked final to avoid the warning. + ~DOTGraphTraitsViewer() {} + private: StringRef Name; }; @@ -99,7 +110,6 @@ : PassInfoMixin> { DOTGraphTraitsPrinter(StringRef GraphName) : Name(GraphName) {} - virtual ~DOTGraphTraitsPrinter() {} /// Return true if this function should be processed. /// @@ -124,6 +134,18 @@ return PreservedAnalyses::all(); }; +protected: + /// Avoid compiler warning "has virtual functions but non-virtual destructor + /// [-Wnon-virtual-dtor]" in derived classes. + /// + /// DOTGraphTraitsPrinter is also used as a mixin for avoiding repeated + /// implementation of printer passes, ie there should be no + /// runtime-polymorphisms/downcasting involving this class and hence no + /// virtual destructor needed. Making this dtor protected stops accidental + /// invocation when the derived class destructor should have been called. + /// Those derived classes sould be marked final to avoid the warning. + ~DOTGraphTraitsPrinter() {} + private: StringRef Name; }; diff --git a/llvm/include/llvm/Analysis/DomPrinter.h b/llvm/include/llvm/Analysis/DomPrinter.h --- a/llvm/include/llvm/Analysis/DomPrinter.h +++ b/llvm/include/llvm/Analysis/DomPrinter.h @@ -74,46 +74,45 @@ } }; -struct DomViewer : public DOTGraphTraitsViewer { +struct DomViewer final : DOTGraphTraitsViewer { DomViewer() : DOTGraphTraitsViewer("dom") {} }; -struct DomOnlyViewer - : public DOTGraphTraitsViewer { +struct DomOnlyViewer final : DOTGraphTraitsViewer { DomOnlyViewer() : DOTGraphTraitsViewer("domonly") {} }; -struct PostDomViewer - : public DOTGraphTraitsViewer { +struct PostDomViewer final + : DOTGraphTraitsViewer { PostDomViewer() : DOTGraphTraitsViewer("postdom") {} }; -struct PostDomOnlyViewer - : public DOTGraphTraitsViewer { +struct PostDomOnlyViewer final + : DOTGraphTraitsViewer { PostDomOnlyViewer() : DOTGraphTraitsViewer("postdomonly") {} }; -struct DomPrinter : public DOTGraphTraitsPrinter { +struct DomPrinter final : DOTGraphTraitsPrinter { DomPrinter() : DOTGraphTraitsPrinter("dom") {} }; -struct DomOnlyPrinter - : public DOTGraphTraitsPrinter { +struct DomOnlyPrinter final + : DOTGraphTraitsPrinter { DomOnlyPrinter() : DOTGraphTraitsPrinter("domonly") {} }; -struct PostDomPrinter - : public DOTGraphTraitsPrinter { +struct PostDomPrinter final + : DOTGraphTraitsPrinter { PostDomPrinter() : DOTGraphTraitsPrinter("postdom") {} }; -struct PostDomOnlyPrinter - : public DOTGraphTraitsPrinter { +struct PostDomOnlyPrinter final + : DOTGraphTraitsPrinter { PostDomOnlyPrinter() : DOTGraphTraitsPrinter("postdomonly") {} };