Skip to content

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

Open
xezon wants to merge 2 commits intoTheSuperHackers:mainfrom
xezon:xezon/refactor-remove-obsolete-return
Open

refactor: Remove superfluous returns at the end of functions#2594
xezon wants to merge 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 removes superfluous return; (and return ;) statements at the end of void functions across ~196 files in the Core/, Generals/, and GeneralsMD/ directories. The changes were applied using the newly added Python script at scripts/cpp/remove_return.py, with some additional manual cleanup in a follow-up commit.

Confidence Score: 5/5

Safe to merge — purely mechanical removal of superfluous void returns with no behavioral change.

All 196 files contain only deletions of trailing return; lines from void functions. The script's column-0 brace guard correctly prevents accidental removal of non-superfluous returns inside nested blocks. Spot-checks across game logic, audio, tools, and template headers all confirmed correct removals.

No files require special attention.

Important Files Changed

Filename Overview
scripts/cpp/remove_return.py New Python script that automates removal of superfluous void returns; logic is sound and conservative (column-0 brace check prevents false positives on nested block returns).
Core/Libraries/Source/WWVegas/WW3D2/sphereobj.cpp Multiple superfluous void returns removed across several methods; all removals are at the end of top-level function bodies.
Core/Libraries/Source/WWVegas/WW3D2/prim_anim.h Template method implementations in header had trailing returns cleaned up; no behavioral change.
GeneralsMD/Code/GameEngine/Source/GameLogic/Object/Update/SpectreGunshipUpdate.cpp Single superfluous return removed from disengageAndDepartAO; correctly caught in follow-up commit.
Core/GameEngine/Source/GameClient/GUI/GameWindow.cpp Returns removed from two empty-body default callback stubs; leaves valid empty function bodies.
Generals/Code/GameEngine/Source/GameLogic/Object/Update/AIUpdate.cpp Four stub functions had their single-line returns cleaned up.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Iterate over all .cpp .h .inl files] --> B[Read each line]
    B --> C{Is last line?}
    C -- Yes --> D[Append unchanged to output]
    C -- No --> E[Find next non-blank line]
    E --> F{Line strips to return semicolon?}
    F -- No --> D
    F -- Yes --> G{Next non-blank line starts with brace at col 0?}
    G -- No --> D
    G -- Yes --> H[Remove the return line]
    H --> I[Pop preceding blank lines from output]
    I --> D
    D --> J{More lines?}
    J -- Yes --> B
    J -- No --> K[Write modified file]
Loading

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

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

1 participant