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
//-----------------------------------------------------------------------------
class SettingsImplGtk : public Settings {
class SettingsImplGtk final : public Settings {
public:
// 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.
@ -198,7 +198,7 @@ SettingsRef GetSettings() {
// Timers
//-----------------------------------------------------------------------------
class TimerImplGtk : public Timer {
class TimerImplGtk final : public Timer {
public:
sigc::connection _connection;
@ -276,7 +276,7 @@ protected:
// Menus
//-----------------------------------------------------------------------------
class MenuItemImplGtk : public MenuItem {
class MenuItemImplGtk final : public MenuItem {
public:
GtkMenuItem gtkMenuItem;
@ -338,7 +338,7 @@ public:
}
};
class MenuImplGtk : public Menu {
class MenuImplGtk final : public Menu {
public:
Gtk::Menu gtkMenu;
std::vector<std::shared_ptr<MenuItemImplGtk>> menuItems;
@ -401,7 +401,7 @@ MenuRef CreateMenu() {
return std::make_shared<MenuImplGtk>();
}
class MenuBarImplGtk : public MenuBar {
class MenuBarImplGtk final : public MenuBar {
public:
Gtk::MenuBar gtkMenuBar;
std::vector<std::shared_ptr<MenuImplGtk>> subMenus;
@ -805,7 +805,7 @@ protected:
// Windows
//-----------------------------------------------------------------------------
class WindowImplGtk : public Window {
class WindowImplGtk final : public Window {
public:
GtkWindow gtkWindow;
MenuBarRef menuBar;
@ -1069,7 +1069,7 @@ void Request3DConnexionEventsForWindow(WindowRef window) {}
// Message dialogs
//-----------------------------------------------------------------------------
class MessageDialogImplGtk : public MessageDialog {
class MessageDialogImplGtk final : public MessageDialog {
public:
Gtk::Image gtkImage;
Gtk::MessageDialog gtkDialog;
@ -1156,7 +1156,7 @@ MessageDialogRef CreateMessageDialog(WindowRef parentWindow) {
// File dialogs
//-----------------------------------------------------------------------------
class FileDialogImplGtk : public FileDialog {
class FileDialogImplGtk final : public FileDialog {
public:
Gtk::FileChooserDialog gtkDialog;
std::vector<std::string> extensions;

View File

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

View File

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

View File

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

View File

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

View File

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