Skip to content

refactor: Add override keyword to virtual function overrides in Tools and set compile option -Wsuggest-override#2394

Open
bobtista wants to merge 10 commits intoTheSuperHackers:mainfrom
bobtista:bobtista/override-keyword-tools
Open

refactor: Add override keyword to virtual function overrides in Tools and set compile option -Wsuggest-override#2394
bobtista wants to merge 10 commits intoTheSuperHackers:mainfrom
bobtista:bobtista/override-keyword-tools

Conversation

@bobtista
Copy link

@bobtista bobtista commented Mar 3, 2026

Summary

  • Add override keyword to virtual function overrides in Tools (WorldBuilder, GUIEdit, wdump)
  • Add -Wsuggest-override compiler warning for GCC and Clang
  • Changes across Generals and GeneralsMD

Context

Part 6/6 of splitting #2101. Depends on #2389 merging first.

Notes

  • 201 files changed
  • All lines retain the virtual keyword
  • The -Wsuggest-override compiler warning ensures future virtual overrides use the keyword

@greptile-apps
Copy link

greptile-apps bot commented Mar 3, 2026

Greptile Summary

This PR (part 6/6 of splitting #2101) adds the override keyword to virtual function overrides across 201 files in the WorldBuilder, GUIEdit, and wdump tools for both Generals and GeneralsMD, and enables -Wsuggest-override for GCC/Clang builds to enforce the convention going forward. The changes are mechanically consistent and correct across the vast majority of files.

Key observations:

  • The const qualifier was correctly added to isZoomLimited() in both wbview3d.cpp stub classes, fixing a pre-existing signature mismatch where the stub was silently not overriding View::isZoomLimited() const.
  • GUIEditDisplay.h's setBorderShroudLevel now gets both virtual and override, resolving the inconsistency noted in prior review threads.
  • Four virtual methods in the WBView3D stub class — isDoingScriptedCamera(), stopDoingScriptedCamera(), lookAt(), and initHeightForMap() — were missed in both Generals/Code/Tools/WorldBuilder/src/wbview3d.cpp and GeneralsMD/Code/Tools/WorldBuilder/src/wbview3d.cpp. Two of these (isDoingScriptedCamera and stopDoingScriptedCamera) override pure virtuals in View. With -Wsuggest-override now enabled, these omissions will produce new compiler warnings on every GCC/Clang build, which directly counters the goal of this PR.

Confidence Score: 4/5

  • Safe to merge with a minor follow-up to add the four missing override annotations in the wbview3d.cpp stub classes.
  • The 201-file change is mechanically correct and introduces no runtime regressions — all changes are annotation-only. The one actionable gap is that four virtual functions in the WBView3D stub were missed, which will generate -Wsuggest-override warnings on the same GCC/Clang toolchains that this PR newly targets. No logic, data integrity, or build-breaking issues were found.
  • Generals/Code/Tools/WorldBuilder/src/wbview3d.cpp and GeneralsMD/Code/Tools/WorldBuilder/src/wbview3d.cpp — four virtual methods are missing override and will produce warnings with the newly enabled -Wsuggest-override flag.

Important Files Changed

Filename Overview
Generals/Code/Tools/WorldBuilder/src/wbview3d.cpp Adds override to most stub virtuals in the WBView3D class; isDoingScriptedCamera, stopDoingScriptedCamera, lookAt, and initHeightForMap were missed and will generate -Wsuggest-override warnings on GCC/Clang. Also correctly adds const to isZoomLimited to fix a pre-existing signature mismatch with the base class.
GeneralsMD/Code/Tools/WorldBuilder/src/wbview3d.cpp Same override additions as the Generals counterpart; same four functions (isDoingScriptedCamera, stopDoingScriptedCamera, lookAt, initHeightForMap) missed and will produce -Wsuggest-override warnings.
cmake/compilers.cmake Adds -Wsuggest-override warning for non-MSVC, non-VS6 compilers (GCC/Clang) inside the if (NOT IS_VS6_BUILD) block. Change is minimal and correctly scoped.
Generals/Code/Tools/GUIEdit/Include/GUIEditDisplay.h Adds override (and the missing virtual) to setBorderShroudLevel in addition to all other overrides in the class, making the file fully consistent.
Generals/Code/Tools/WorldBuilder/include/CUndoable.h Consistently adds virtual + override to all destructors and Do/Undo/Redo overrides in the Undoable hierarchy; Undoable inherits RefCountClass which has a virtual destructor, so the override specifier on the destructor is valid.
Generals/Code/Tools/WorldBuilder/src/WorldBuilderDoc.cpp Adds override to the write method in three local OutputStream subclasses (MFCFileOutputStream, CachedMFCFileOutputStream, CompressedCachedMFCFileOutputStream); straightforward and correct.
GeneralsMD/Code/Tools/wdump/wdump.cpp Adds override to ParseParam in CWDumpCommandLineInfo and DoDataExchange in CAboutDlg; clean, minimal change.

Class Diagram

%%{init: {'theme': 'neutral'}}%%
classDiagram
    class View {
        +virtual Bool isZoomLimited() const
        +virtual Bool isDoingScriptedCamera() = 0
        +virtual void stopDoingScriptedCamera() = 0
        +virtual void lookAt(const Coord3D*o)
        +virtual void initHeightForMap()
        +virtual void forceRedraw() = 0
    }

    class WBView3D {
        +virtual Bool isZoomLimited() const override ✅
        +virtual Bool isDoingScriptedCamera() ⚠️ missing override
        +virtual void stopDoingScriptedCamera() ⚠️ missing override
        +virtual void lookAt(const Coord3D*o) ⚠️ missing override
        +virtual void initHeightForMap() ⚠️ missing override
        +virtual void forceRedraw() override ✅
    }

    class RefCountClass {
        +virtual ~RefCountClass()
    }

    class Undoable {
        +virtual ~Undoable() override ✅
        +virtual void Do() = 0
        +virtual void Undo() = 0
        +virtual void Redo()
    }

    class WBDocUndoable {
        +virtual ~WBDocUndoable() override ✅
        +virtual void Do() override ✅
        +virtual void Undo() override ✅
        +virtual void Redo() override ✅
    }

    View <|-- WBView3D
    RefCountClass <|-- Undoable
    Undoable <|-- WBDocUndoable
Loading
Prompt To Fix All With AI
This is a comment left during a code review.
Path: Generals/Code/Tools/WorldBuilder/src/wbview3d.cpp
Line: 199-204

Comment:
**Missing `override` on several stub virtuals**

The `WBView3D` stub class has four virtual functions that do override `View` base-class virtuals but were not annotated with `override` in this PR. With `-Wsuggest-override` now enabled for GCC/Clang (added in `cmake/compilers.cmake`), these will generate new compiler warnings on every non-MSVC build, directly undermining the goal of this change set.

The functions and their base-class counterparts in `View.h`:

| Stub function | Base declaration |
|---|---|
| `isDoingScriptedCamera()` | `virtual Bool isDoingScriptedCamera() = 0` (line 174) |
| `stopDoingScriptedCamera()` | `virtual void stopDoingScriptedCamera() = 0` (line 175) |
| `lookAt( const Coord3D *o )` | `virtual void lookAt( const Coord3D *o )` (line 133) |
| `initHeightForMap( void )` | `virtual void initHeightForMap() {}` (line 134) |

The same four functions are identically missing `override` in `GeneralsMD/Code/Tools/WorldBuilder/src/wbview3d.cpp` (lines 200–204).

Suggested fix for both files:
```suggestion
	virtual Bool isDoingScriptedCamera() override { return false; }
	virtual void stopDoingScriptedCamera() override {}

	virtual void lookAt( const Coord3D *o ) override {};														///< Center the view on the given coordinate
	virtual void initHeightForMap( void ) override {};														///<  Init the camera height for the map at the current position.
```

How can I resolve this? If you propose a fix, please make it concise.

Last reviewed commit: f5d1564

@xezon xezon added the Refactor Edits the code with insignificant behavior changes, is never user facing label Mar 10, 2026
@bobtista bobtista force-pushed the bobtista/override-keyword-tools branch from 1630354 to b7df0dc Compare March 11, 2026 01:48
@Skyaero42
Copy link

Might want to do a quick spacing check before I review?

@bobtista
Copy link
Author

Might want to do a quick spacing check before I review?

Looks good - found some mixed tab/space stuff for indentation but the override {} spacing seems good

Copy link

@Skyaero42 Skyaero42 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good

@xezon xezon changed the title refactor(Tools): Add override keyword and -Wsuggest-override warning refactor(Tools): Add override keyword to virtual function overrides in Tools and set compile option -Wsuggest-override Mar 17, 2026
@xezon xezon changed the title refactor(Tools): Add override keyword to virtual function overrides in Tools and set compile option -Wsuggest-override refactor: Add override keyword to virtual function overrides in Tools and set compile option -Wsuggest-override Mar 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Refactor Edits the code with insignificant behavior changes, is never user facing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants