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
Open
Conversation
|
| 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
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
1630354 to
b7df0dc
Compare
|
Might want to do a quick spacing check before I review? |
Author
Looks good - found some mixed tab/space stuff for indentation but the override {} spacing seems good |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
overridekeyword to virtual function overrides in Tools (WorldBuilder, GUIEdit, wdump)-Wsuggest-overridecompiler warning for GCC and ClangContext
Part 6/6 of splitting #2101. Depends on #2389 merging first.
Notes
virtualkeyword-Wsuggest-overridecompiler warning ensures future virtual overrides use the keyword