Add final qualifiers where applicable.

We have a lot of classes with virtual functions but no virtual
destructor, mostly under render/. While this is not a problem
due to how our hierarchy is structured, some versions of clang
warn about this on the delete statement inside shared_ptr.

We could add a virtual destructor, but adding final qualifiers
expresses intent better, is generally more efficient (since it allows
devirtualizing most virtual calls in render/), and solves
the potential problem clang is warning us about.
This commit is contained in:
whitequark 2018-07-19 00:11:04 +00:00
parent 4f52167a78
commit fb138f496a
6 changed files with 36 additions and 36 deletions

View File

@ -63,7 +63,7 @@ void FatalError(std::string message) {
// Settings // Settings
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
class SettingsImplGtk : public Settings { class SettingsImplGtk final : public Settings {
public: public:
// Why aren't we using GSettings? Two reasons. It doesn't allow to easily see whether // Why aren't we using GSettings? Two reasons. It doesn't allow to easily see whether
// the setting had the default value, and it requires to install a schema globally. // the setting had the default value, and it requires to install a schema globally.
@ -198,7 +198,7 @@ SettingsRef GetSettings() {
// Timers // Timers
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
class TimerImplGtk : public Timer { class TimerImplGtk final : public Timer {
public: public:
sigc::connection _connection; sigc::connection _connection;
@ -276,7 +276,7 @@ protected:
// Menus // Menus
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
class MenuItemImplGtk : public MenuItem { class MenuItemImplGtk final : public MenuItem {
public: public:
GtkMenuItem gtkMenuItem; GtkMenuItem gtkMenuItem;
@ -338,7 +338,7 @@ public:
} }
}; };
class MenuImplGtk : public Menu { class MenuImplGtk final : public Menu {
public: public:
Gtk::Menu gtkMenu; Gtk::Menu gtkMenu;
std::vector<std::shared_ptr<MenuItemImplGtk>> menuItems; std::vector<std::shared_ptr<MenuItemImplGtk>> menuItems;
@ -401,7 +401,7 @@ MenuRef CreateMenu() {
return std::make_shared<MenuImplGtk>(); return std::make_shared<MenuImplGtk>();
} }
class MenuBarImplGtk : public MenuBar { class MenuBarImplGtk final : public MenuBar {
public: public:
Gtk::MenuBar gtkMenuBar; Gtk::MenuBar gtkMenuBar;
std::vector<std::shared_ptr<MenuImplGtk>> subMenus; std::vector<std::shared_ptr<MenuImplGtk>> subMenus;
@ -805,7 +805,7 @@ protected:
// Windows // Windows
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
class WindowImplGtk : public Window { class WindowImplGtk final : public Window {
public: public:
GtkWindow gtkWindow; GtkWindow gtkWindow;
MenuBarRef menuBar; MenuBarRef menuBar;
@ -1069,7 +1069,7 @@ void Request3DConnexionEventsForWindow(WindowRef window) {}
// Message dialogs // Message dialogs
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
class MessageDialogImplGtk : public MessageDialog { class MessageDialogImplGtk final : public MessageDialog {
public: public:
Gtk::Image gtkImage; Gtk::Image gtkImage;
Gtk::MessageDialog gtkDialog; Gtk::MessageDialog gtkDialog;
@ -1156,7 +1156,7 @@ MessageDialogRef CreateMessageDialog(WindowRef parentWindow) {
// File dialogs // File dialogs
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
class FileDialogImplGtk : public FileDialog { class FileDialogImplGtk final : public FileDialog {
public: public:
Gtk::FileChooserDialog gtkDialog; Gtk::FileChooserDialog gtkDialog;
std::vector<std::string> extensions; std::vector<std::string> extensions;

View File

@ -93,7 +93,7 @@ void FatalError(std::string message) {
// Settings // Settings
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
class SettingsImplCocoa : public Settings { class SettingsImplCocoa final : public Settings {
public: public:
NSUserDefaults *userDefaults; NSUserDefaults *userDefaults;
@ -159,7 +159,7 @@ SettingsRef GetSettings() {
// Timers // Timers
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
class TimerImplCocoa : public Timer { class TimerImplCocoa final : public Timer {
public: public:
NSTimer *timer; NSTimer *timer;
@ -194,7 +194,7 @@ TimerRef CreateTimer() {
// Menus // Menus
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
class MenuItemImplCocoa : public MenuItem { class MenuItemImplCocoa final : public MenuItem {
public: public:
SSFunction *ssFunction; SSFunction *ssFunction;
NSMenuItem *nsMenuItem; NSMenuItem *nsMenuItem;
@ -244,7 +244,7 @@ public:
} }
}; };
class MenuImplCocoa : public Menu { class MenuImplCocoa final : public Menu {
public: public:
NSMenu *nsMenu; NSMenu *nsMenu;
@ -298,7 +298,7 @@ MenuRef CreateMenu() {
return std::make_shared<MenuImplCocoa>(); return std::make_shared<MenuImplCocoa>();
} }
class MenuBarImplCocoa : public MenuBar { class MenuBarImplCocoa final : public MenuBar {
public: public:
NSMenu *nsMenuBar; NSMenu *nsMenuBar;
@ -756,7 +756,7 @@ namespace Platform {
// Windows // Windows
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
class WindowImplCocoa : public Window { class WindowImplCocoa final : public Window {
public: public:
NSWindow *nsWindow; NSWindow *nsWindow;
SSWindowDelegate *ssWindowDelegate; SSWindowDelegate *ssWindowDelegate;
@ -1159,7 +1159,7 @@ void Request3DConnexionEventsForWindow(WindowRef window) {
// Message dialogs // Message dialogs
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
class MessageDialogImplCocoa : public MessageDialog { class MessageDialogImplCocoa final : public MessageDialog {
public: public:
NSAlert *nsAlert = [[NSAlert alloc] init]; NSAlert *nsAlert = [[NSAlert alloc] init];
NSWindow *nsWindow; NSWindow *nsWindow;
@ -1294,7 +1294,7 @@ public:
} }
}; };
class OpenFileDialogImplCocoa : public FileDialogImplCocoa { class OpenFileDialogImplCocoa final : public FileDialogImplCocoa {
public: public:
NSMutableArray *nsFilter = [[NSMutableArray alloc] init]; NSMutableArray *nsFilter = [[NSMutableArray alloc] init];
@ -1310,7 +1310,7 @@ public:
} }
}; };
class SaveFileDialogImplCocoa : public FileDialogImplCocoa { class SaveFileDialogImplCocoa final : public FileDialogImplCocoa {
public: public:
NSMutableArray *nsFilters = [[NSMutableArray alloc] init]; NSMutableArray *nsFilters = [[NSMutableArray alloc] init];
SSSaveFormatAccessory *ssAccessory = nil; SSSaveFormatAccessory *ssAccessory = nil;

View File

@ -51,7 +51,7 @@ void FatalError(std::string message) {
// Settings // Settings
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
class SettingsImplDummy : public Settings { class SettingsImplDummy final : public Settings {
public: public:
void FreezeInt(const std::string &key, uint32_t value) {} void FreezeInt(const std::string &key, uint32_t value) {}
@ -83,7 +83,7 @@ SettingsRef GetSettings() {
// Timers // Timers
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
class TimerImplDummy : public Timer { class TimerImplDummy final : public Timer {
public: public:
void RunAfter(unsigned milliseconds) override {} void RunAfter(unsigned milliseconds) override {}
}; };

View File

@ -143,7 +143,7 @@ void FatalError(std::string message) {
// Settings // Settings
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
class SettingsImplWin32 : public Settings { class SettingsImplWin32 final : public Settings {
public: public:
HKEY hKey = NULL; HKEY hKey = NULL;
@ -224,7 +224,7 @@ SettingsRef GetSettings() {
// Timers // Timers
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
class TimerImplWin32 : public Timer { class TimerImplWin32 final : public Timer {
public: public:
static HWND WindowHandle() { static HWND WindowHandle() {
static HWND hTimerWnd; static HWND hTimerWnd;
@ -267,7 +267,7 @@ TimerRef CreateTimer() {
class MenuImplWin32; class MenuImplWin32;
class MenuItemImplWin32 : public MenuItem { class MenuItemImplWin32 final : public MenuItem {
public: public:
std::shared_ptr<MenuImplWin32> menu; std::shared_ptr<MenuImplWin32> menu;
@ -340,7 +340,7 @@ public:
int64_t contextMenuPopTime = 0; int64_t contextMenuPopTime = 0;
class MenuImplWin32 : public Menu { class MenuImplWin32 final : public Menu {
public: public:
HMENU hMenu; HMENU hMenu;
@ -426,7 +426,7 @@ MenuRef CreateMenu() {
return menu; return menu;
} }
class MenuBarImplWin32 : public MenuBar { class MenuBarImplWin32 final : public MenuBar {
public: public:
HMENU hMenuBar; HMENU hMenuBar;
@ -471,7 +471,7 @@ MenuBarRef GetOrCreateMainMenu(bool *unique) {
#define SCROLLBAR_UNIT 65536 #define SCROLLBAR_UNIT 65536
class WindowImplWin32 : public Window { class WindowImplWin32 final : public Window {
public: public:
HWND hWindow = NULL; HWND hWindow = NULL;
HWND hTooltip = NULL; HWND hTooltip = NULL;
@ -1357,7 +1357,7 @@ void Request3DConnexionEventsForWindow(WindowRef window) {}
// Message dialogs // Message dialogs
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
class MessageDialogImplWin32 : public MessageDialog { class MessageDialogImplWin32 final : public MessageDialog {
public: public:
MSGBOXPARAMSW mbp = {}; MSGBOXPARAMSW mbp = {};
@ -1467,7 +1467,7 @@ MessageDialogRef CreateMessageDialog(WindowRef parentWindow) {
// File dialogs // File dialogs
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
class FileDialogImplWin32 : public FileDialog { class FileDialogImplWin32 final : public FileDialog {
public: public:
OPENFILENAMEW ofn = {}; OPENFILENAMEW ofn = {};
bool isSaveDialog; bool isSaveDialog;

View File

@ -166,7 +166,7 @@ static void ssglFillPattern(Canvas::FillPattern pattern) {
// OpenGL 1 / compatibility profile based renderer // OpenGL 1 / compatibility profile based renderer
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
class OpenGl1Renderer : public ViewportCanvas { class OpenGl1Renderer final : public ViewportCanvas {
public: public:
Camera camera; Camera camera;
Lighting lighting; Lighting lighting;

View File

@ -40,7 +40,7 @@ public:
}; };
// A canvas that uses the core OpenGL 3 profile, for desktop systems. // A canvas that uses the core OpenGL 3 profile, for desktop systems.
class OpenGl2Renderer : public ViewportCanvas { class OpenGl2Renderer final : public ViewportCanvas {
public: public:
struct SEdgeListItem { struct SEdgeListItem {
hStroke h; hStroke h;
@ -716,7 +716,7 @@ public:
virtual void Remove(OpenGl2Renderer *renderer) = 0; virtual void Remove(OpenGl2Renderer *renderer) = 0;
}; };
class EdgeDrawCall : public DrawCall { class EdgeDrawCall final : public DrawCall {
public: public:
// Key // Key
Canvas::Stroke stroke; Canvas::Stroke stroke;
@ -745,7 +745,7 @@ public:
} }
}; };
class OutlineDrawCall : public DrawCall { class OutlineDrawCall final : public DrawCall {
public: public:
// Key // Key
Canvas::Stroke stroke; Canvas::Stroke stroke;
@ -777,7 +777,7 @@ public:
} }
}; };
class PointDrawCall : public DrawCall { class PointDrawCall final : public DrawCall {
public: public:
// Key // Key
Canvas::Stroke stroke; Canvas::Stroke stroke;
@ -806,7 +806,7 @@ public:
} }
}; };
class PixmapDrawCall : public DrawCall { class PixmapDrawCall final : public DrawCall {
public: public:
// Key // Key
Canvas::Fill fill; Canvas::Fill fill;
@ -842,7 +842,7 @@ public:
} }
}; };
class MeshDrawCall : public DrawCall { class MeshDrawCall final : public DrawCall {
public: public:
// Key // Key
Canvas::Fill fillFront; Canvas::Fill fillFront;
@ -903,7 +903,7 @@ public:
}; };
struct CompareDrawCall { struct CompareDrawCall {
bool operator()(const std::shared_ptr<DrawCall> &a, const std::shared_ptr<DrawCall> &b) { bool operator()(const std::shared_ptr<DrawCall> &a, const std::shared_ptr<DrawCall> &b) const {
const Canvas::Layer stackup[] = { const Canvas::Layer stackup[] = {
Canvas::Layer::BACK, Canvas::Layer::BACK,
Canvas::Layer::DEPTH_ONLY, Canvas::Layer::DEPTH_ONLY,
@ -924,7 +924,7 @@ struct CompareDrawCall {
} }
}; };
class OpenGl2RendererBatch : public BatchCanvas { class OpenGl2RendererBatch final : public BatchCanvas {
public: public:
struct EdgeBuffer { struct EdgeBuffer {
hStroke h; hStroke h;