Skip to content

chore: Prevent conflict between clang-format and pre-C++11 nested template parsing#2760

Open
DevGeniusCode wants to merge 1 commit into
TheSuperHackers:mainfrom
DevGeniusCode:clang/fix-typedef-extractor
Open

chore: Prevent conflict between clang-format and pre-C++11 nested template parsing#2760
DevGeniusCode wants to merge 1 commit into
TheSuperHackers:mainfrom
DevGeniusCode:clang/fix-typedef-extractor

Conversation

@DevGeniusCode
Copy link
Copy Markdown

This PR resolves compilation errors in pre-C++11 compilers (such as VC6) caused by the >> token sequence in nested template declarations.

Instead of restructuring the code with typedefs, the issue is addressed by safely separating the consecutive closing angle brackets with an empty comment: >/* */>. This prevents the compiler from misinterpreting the sequence as a right-shift operator while preserving the original code structure and type definitions intact.

Key Details:

  • Scope: A total of 68 instances of nested templates (found by searching for > >) were updated using this pattern.
  • Edge Cases & Comments: Nested templates located within code comments were intentionally left unchanged.

@DevGeniusCode DevGeniusCode added the Refactor Edits the code with insignificant behavior changes, is never user facing label May 30, 2026
@greptile-apps
Copy link
Copy Markdown

greptile-apps Bot commented May 30, 2026

Greptile Summary

This PR applies a mechanical refactoring across 48 files to replace the pre-existing > > whitespace separator in nested template declarations with an empty C-style comment >/**/>, targeting pre-C++11 compiler compatibility (specifically VC6, which could misparse >> as the right-shift operator).

  • 68 instances updated consistently across typedef declarations, class base specifiers, using declarations, and function return types in both the Generals and GeneralsMD codebases.
  • The approach is syntactically valid: a block comment between the two closing angle brackets is sufficient to prevent the tokenizer from interpreting them as >>. This is an established alternative to the > > whitespace workaround already present in the original code.

Confidence Score: 5/5

Safe to merge — all 68 changes are mechanical token-level substitutions with no runtime behavior impact.

Every change replaces an existing > > whitespace separator with an equivalent >/**/> empty-comment separator inside template angle brackets. Neither form affects generated code; both prevent the >> right-shift ambiguity in pre-C++11 compilers. The transformation is applied consistently across the entire codebase and introduces no new logic, types, or dependencies.

No files require special attention. The changes in AudioEvents.h touch using declarations where the original > >:: pattern was already unambiguous, but the substitution is still syntactically correct and harmless.

Important Files Changed

Filename Overview
Core/Libraries/Source/WWVegas/WWAudio/AudioEvents.h Applies >/**/ fix to class base specifier and four using declarations; the using declarations had > >:: not > > so changes are redundant but harmless
Core/Libraries/Source/WWVegas/WWLib/STLUtils.h Four > > separators in template return types and return expressions replaced with >/**/>; correct and complete
Core/Tools/matchbot/wlib/ustring.h Three instances fixed: class inheritance and two pointer declarations with nested templates; all correct
Generals/Code/GameEngine/Source/Common/PerfTimer.cpp Single fix for std::vector< std::pair<...> > typedef; comment correctly inserted between pair's > and vector's >
Core/GameEngine/Include/Common/STLTypedefs.h Two std::map typedefs with std::less<...> comparator fixed; consistent with rest of PR
Generals/Code/GameEngine/Include/GameLogic/GameLogic.h Three std::hash_map typedefs updated; one for ObjectPtrHash (public), two for private BuildableMap and ControlBarOverrideMap
GeneralsMD/Code/GameEngine/Include/GameLogic/GameLogic.h Mirror of Generals GameLogic.h with same two private typedef fixes applied correctly
Core/GameEngine/Include/Common/GameAudio.h Two fixes: AudioEventInfoHash typedef and m_adjustedVolumes member declaration; both correct

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["Pre-C++11 Compiler (VC6)"] -->|"tokenizes '>>' as right-shift"| B["Compilation Error"]
    A -->|"sees '> >'"| C["Valid Template Close"]
    A -->|"sees '>/**/>'"| D["Valid Template Close"]

    subgraph Before["Before (original)"]
        E["std::map&lt;Key, Val, std::less&lt;Key&gt; &gt;"]
    end

    subgraph After["After (this PR)"]
        F["std::map&lt;Key, Val, std::less&lt;Key&gt;/**/ &gt;"]
    end

    E -->|"space separator already present"| C
    F -->|"empty comment separator"| D

    C --> G["Compiles OK"]
    D --> G
Loading

Reviews (2): Last reviewed commit: "refactor: Fix pre-C++11 nested template ..." | Re-trigger Greptile

Copy link
Copy Markdown

@xezon xezon left a comment

Choose a reason for hiding this comment

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

Silly we need to do that 🥲

Comment thread Core/GameEngine/Include/Common/FileSystem.h Outdated
@DevGeniusCode DevGeniusCode force-pushed the clang/fix-typedef-extractor branch from 3438f4a to 5bdfbee Compare June 1, 2026 09:36
@xezon
Copy link
Copy Markdown

xezon commented Jun 1, 2026

Does clang-format preserve the space when the clang format language is set to c++98 ? Or will this cause other issues then (such as failing to recognize constexpr, override, etc)?

@xezon xezon changed the title refactor: Fix pre-C++11 nested template parsing chore: Prevent conflict between clang-format and pre-C++11 nested template parsing Jun 1, 2026
@DevGeniusCode
Copy link
Copy Markdown
Author

The standard is set to c++20, no c++03

@xezon
Copy link
Copy Markdown

xezon commented Jun 3, 2026

Let me rephrase my question: What happens to the template character parse when changing the clang format language to before c++11 ?

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.

2 participants