Skip to content

refactor: Remove superfluous returns at the end of functions#2594

Merged
xezon merged 2 commits intoTheSuperHackers:mainfrom
xezon:xezon/refactor-remove-obsolete-return
Apr 18, 2026
Merged

refactor: Remove superfluous returns at the end of functions#2594
xezon merged 2 commits intoTheSuperHackers:mainfrom
xezon:xezon/refactor-remove-obsolete-return

Conversation

@xezon
Copy link
Copy Markdown

@xezon xezon commented Apr 12, 2026

This change removes superfluous returns at the end of functions.

Applied with python script and a bit of hand holding.

@xezon xezon added the Refactor Edits the code with insignificant behavior changes, is never user facing label Apr 12, 2026
@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented Apr 12, 2026

Greptile Summary

This PR performs a mechanical, codebase-wide style cleanup by removing superfluous return; statements at the end of void functions across 194 C++ source files, along with the Python script (scripts/cpp/remove_return.py) used to apply the changes. No logic is altered — every removed return was a no-op at the end of a function body.

Confidence Score: 5/5

Safe to merge — purely cosmetic refactoring with no behavioral changes.

All 195 changed files only remove trailing return; or return ; statements that were no-ops at the end of void functions. The driving script correctly gates removal on the closing brace being at column 0 (function-level brace), making false-positive removals of non-superfluous returns effectively impossible with typical indentation. The sole finding is a P2 style note about the script's own trailing return.

No files require special attention.

Important Files Changed

Filename Overview
scripts/cpp/remove_return.py New helper script that drives the mass refactoring; logic is sound but contains a superfluous return at the end of its own main().
Core/GameEngine/Source/GameClient/GUI/GameWindow.cpp Removes two trailing return; statements from empty void stubs — correct and safe.
Core/Libraries/Source/WWVegas/WW3D2/dx8wrapper.cpp Removes four trailing return ; statements from void methods; no logic change.
Core/Libraries/Source/WWVegas/WWLib/wwstring.h Removes multiple trailing return ; statements from inline constructors and helpers in the header — all correctly identified as superfluous.
Generals/Code/GameEngine/Source/GameLogic/AI/AIPlayer.cpp Single return; removal from buildUpgrade; straightforward and correct.
GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/SpectreGunshipUpdate.cpp Removes trailing return; and its preceding blank line from disengageAndDepartAO; correct.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[remove_return.py] --> B[Glob cpp/h/inl files across Core, Generals, GeneralsMD]
    B --> C{For each line}
    C --> D{Starts with return-semicolon?}
    D -- No --> E[Keep line as-is]
    D -- Yes --> F{Next non-blank line starts with closing-brace at column 0?}
    F -- No --> E
    F -- Yes --> G[Remove return line and preceding blank lines]
    G --> H[Write cleaned file]
    E --> H
Loading
Prompt To Fix All With AI
This is a comment left during a code review.
Path: scripts/cpp/remove_return.py
Line: 63

Comment:
**Superfluous `return` in the script itself**

The script that removes superfluous `return` statements at the end of functions itself contains one at the end of `main()`. Since the script only processes C++ files it won't self-apply, but it's a minor irony worth noting.

```suggestion
    main()
```

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

Reviews (2): Last reviewed commit: "Remove a few more" | Re-trigger Greptile

@Caball009
Copy link
Copy Markdown

Do you plan to get rid of the now empty lines as well?

@xezon
Copy link
Copy Markdown
Author

xezon commented Apr 13, 2026

The script only removed empty lines above the return. Not below. I think it is fine.

@xezon xezon force-pushed the xezon/refactor-remove-obsolete-return branch from a46ae11 to 4fd5138 Compare April 13, 2026 21:12
Copy link
Copy Markdown

@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.

I agree the extra lines are fine. Based on a small sample it seems to fit in the style of the respective file anyways.

@xezon xezon merged commit ccd9c1d into TheSuperHackers:main Apr 18, 2026
17 checks passed
@xezon xezon deleted the xezon/refactor-remove-obsolete-return branch April 18, 2026 18:52
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.

Remove unnecessary return statements at function end

3 participants