Skip to content

Commit

Permalink
Add final qualifiers where applicable.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
whitequark committed Jul 19, 2018
1 parent 4f52167 commit fb138f4
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 36 deletions.
16 changes: 8 additions & 8 deletions src/platform/guigtk.cpp
Expand Up @@ -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.
Expand Down Expand Up @@ -198,7 +198,7 @@ SettingsRef GetSettings() {
// Timers
//-----------------------------------------------------------------------------

class TimerImplGtk : public Timer {
class TimerImplGtk final : public Timer {
public:
sigc::connection _connection;

Expand Down Expand Up @@ -276,7 +276,7 @@ class GtkMenuItem : public Gtk::CheckMenuItem {
// Menus
//-----------------------------------------------------------------------------

class MenuItemImplGtk : public MenuItem {
class MenuItemImplGtk final : public MenuItem {
public:
GtkMenuItem gtkMenuItem;

Expand Down Expand Up @@ -338,7 +338,7 @@ class MenuItemImplGtk : public MenuItem {
}
};

class MenuImplGtk : public Menu {
class MenuImplGtk final : public Menu {
public:
Gtk::Menu gtkMenu;
std::vector<std::shared_ptr<MenuItemImplGtk>> menuItems;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -805,7 +805,7 @@ class GtkWindow : public Gtk::Window {
// Windows
//-----------------------------------------------------------------------------

class WindowImplGtk : public Window {
class WindowImplGtk final : public Window {
public:
GtkWindow gtkWindow;
MenuBarRef menuBar;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
18 changes: 9 additions & 9 deletions src/platform/guimac.mm
Expand Up @@ -93,7 +93,7 @@ void FatalError(std::string message) {
// Settings
//-----------------------------------------------------------------------------

class SettingsImplCocoa : public Settings {
class SettingsImplCocoa final : public Settings {
public:
NSUserDefaults *userDefaults;

Expand Down Expand Up @@ -159,7 +159,7 @@ SettingsRef GetSettings() {
// Timers
//-----------------------------------------------------------------------------

class TimerImplCocoa : public Timer {
class TimerImplCocoa final : public Timer {
public:
NSTimer *timer;

Expand Down Expand Up @@ -194,7 +194,7 @@ TimerRef CreateTimer() {
// Menus
//-----------------------------------------------------------------------------

class MenuItemImplCocoa : public MenuItem {
class MenuItemImplCocoa final : public MenuItem {
public:
SSFunction *ssFunction;
NSMenuItem *nsMenuItem;
Expand Down Expand Up @@ -244,7 +244,7 @@ void SetEnabled(bool enabled) override {
}
};

class MenuImplCocoa : public Menu {
class MenuImplCocoa final : public Menu {
public:
NSMenu *nsMenu;

Expand Down Expand Up @@ -298,7 +298,7 @@ MenuRef CreateMenu() {
return std::make_shared<MenuImplCocoa>();
}

class MenuBarImplCocoa : public MenuBar {
class MenuBarImplCocoa final : public MenuBar {
public:
NSMenu *nsMenuBar;

Expand Down Expand Up @@ -756,7 +756,7 @@ - (void)windowDidExitFullScreen:(NSNotification *)notification {
// Windows
//-----------------------------------------------------------------------------

class WindowImplCocoa : public Window {
class WindowImplCocoa final : public Window {
public:
NSWindow *nsWindow;
SSWindowDelegate *ssWindowDelegate;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1294,7 +1294,7 @@ bool RunModal() override {
}
};

class OpenFileDialogImplCocoa : public FileDialogImplCocoa {
class OpenFileDialogImplCocoa final : public FileDialogImplCocoa {
public:
NSMutableArray *nsFilter = [[NSMutableArray alloc] init];

Expand All @@ -1310,7 +1310,7 @@ void AddFilter(std::string name, std::vector<std::string> extensions) override {
}
};

class SaveFileDialogImplCocoa : public FileDialogImplCocoa {
class SaveFileDialogImplCocoa final : public FileDialogImplCocoa {
public:
NSMutableArray *nsFilters = [[NSMutableArray alloc] init];
SSSaveFormatAccessory *ssAccessory = nil;
Expand Down
4 changes: 2 additions & 2 deletions src/platform/guinone.cpp
Expand Up @@ -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) {}

Expand Down Expand Up @@ -83,7 +83,7 @@ SettingsRef GetSettings() {
// Timers
//-----------------------------------------------------------------------------

class TimerImplDummy : public Timer {
class TimerImplDummy final : public Timer {
public:
void RunAfter(unsigned milliseconds) override {}
};
Expand Down
16 changes: 8 additions & 8 deletions src/platform/guiwin.cpp
Expand Up @@ -143,7 +143,7 @@ void FatalError(std::string message) {
// Settings
//-----------------------------------------------------------------------------

class SettingsImplWin32 : public Settings {
class SettingsImplWin32 final : public Settings {
public:
HKEY hKey = NULL;

Expand Down Expand Up @@ -224,7 +224,7 @@ SettingsRef GetSettings() {
// Timers
//-----------------------------------------------------------------------------

class TimerImplWin32 : public Timer {
class TimerImplWin32 final : public Timer {
public:
static HWND WindowHandle() {
static HWND hTimerWnd;
Expand Down Expand Up @@ -267,7 +267,7 @@ TimerRef CreateTimer() {

class MenuImplWin32;

class MenuItemImplWin32 : public MenuItem {
class MenuItemImplWin32 final : public MenuItem {
public:
std::shared_ptr<MenuImplWin32> menu;

Expand Down Expand Up @@ -340,7 +340,7 @@ class MenuItemImplWin32 : public MenuItem {

int64_t contextMenuPopTime = 0;

class MenuImplWin32 : public Menu {
class MenuImplWin32 final : public Menu {
public:
HMENU hMenu;

Expand Down Expand Up @@ -426,7 +426,7 @@ MenuRef CreateMenu() {
return menu;
}

class MenuBarImplWin32 : public MenuBar {
class MenuBarImplWin32 final : public MenuBar {
public:
HMENU hMenuBar;

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -1357,7 +1357,7 @@ void Request3DConnexionEventsForWindow(WindowRef window) {}
// Message dialogs
//-----------------------------------------------------------------------------

class MessageDialogImplWin32 : public MessageDialog {
class MessageDialogImplWin32 final : public MessageDialog {
public:
MSGBOXPARAMSW mbp = {};

Expand Down Expand Up @@ -1467,7 +1467,7 @@ MessageDialogRef CreateMessageDialog(WindowRef parentWindow) {
// File dialogs
//-----------------------------------------------------------------------------

class FileDialogImplWin32 : public FileDialog {
class FileDialogImplWin32 final : public FileDialog {
public:
OPENFILENAMEW ofn = {};
bool isSaveDialog;
Expand Down
2 changes: 1 addition & 1 deletion src/render/rendergl1.cpp
Expand Up @@ -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;
Expand Down
16 changes: 8 additions & 8 deletions src/render/rendergl3.cpp
Expand Up @@ -40,7 +40,7 @@ class TextureCache {
};

// 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;
Expand Down Expand Up @@ -716,7 +716,7 @@ class DrawCall {
virtual void Remove(OpenGl2Renderer *renderer) = 0;
};

class EdgeDrawCall : public DrawCall {
class EdgeDrawCall final : public DrawCall {
public:
// Key
Canvas::Stroke stroke;
Expand Down Expand Up @@ -745,7 +745,7 @@ class EdgeDrawCall : public DrawCall {
}
};

class OutlineDrawCall : public DrawCall {
class OutlineDrawCall final : public DrawCall {
public:
// Key
Canvas::Stroke stroke;
Expand Down Expand Up @@ -777,7 +777,7 @@ class OutlineDrawCall : public DrawCall {
}
};

class PointDrawCall : public DrawCall {
class PointDrawCall final : public DrawCall {
public:
// Key
Canvas::Stroke stroke;
Expand Down Expand Up @@ -806,7 +806,7 @@ class PointDrawCall : public DrawCall {
}
};

class PixmapDrawCall : public DrawCall {
class PixmapDrawCall final : public DrawCall {
public:
// Key
Canvas::Fill fill;
Expand Down Expand Up @@ -842,7 +842,7 @@ class PixmapDrawCall : public DrawCall {
}
};

class MeshDrawCall : public DrawCall {
class MeshDrawCall final : public DrawCall {
public:
// Key
Canvas::Fill fillFront;
Expand Down Expand Up @@ -903,7 +903,7 @@ class MeshDrawCall : public DrawCall {
};

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,
Expand All @@ -924,7 +924,7 @@ struct CompareDrawCall {
}
};

class OpenGl2RendererBatch : public BatchCanvas {
class OpenGl2RendererBatch final : public BatchCanvas {
public:
struct EdgeBuffer {
hStroke h;
Expand Down

0 comments on commit fb138f4

Please sign in to comment.