Repository navigation
Make headers safe against <windows.h> min/max macros - #6
Merged
Merged
Conversation
<windows.h> without NOMINMAX defines min and max as function-like macros, which break calls like std::numeric_limits<int>::max() (Span.h's Detail::fitsInt) in any consumer that includes it first. Wrapping the name in parentheses suppresses macro expansion, so the headers no longer depend on the consumer defining NOMINMAX.
Includes <windows.h> with NOMINMAX explicitly undefined, then every public header, so an unparenthesized min/max call fails the Windows build.
eyalamirmusic
marked this pull request as ready for review
November 17, 2026 01:47
eyalamirmusic
force-pushed
the
orch/windows-minmax
branch
from
November 17, 2026 01:53
8d5f09e to
9477eaa
Compare
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.
What and why
<windows.h>withoutNOMINMAXdefinesminandmaxas function-like macros. A consumer that includes it before this library breaks on calls likestd::numeric_limits<int>::max()inSpan.h'sDetail::fitsInt. PureDOOM ran into this insrc/DOOM/Host/Host.cppand worked around it withNOMINMAX. eacp only avoids it because its ownWinInclude.hdefinesNOMINMAX. A header-only library shouldn't rely on its consumers doing that.Fix (commit 1): I checked every header and test source for macro-vulnerable calls and put the name in parentheses, the standard way to stop the macro expanding:
(std::numeric_limits<T>::max)()/min:Span.h(fitsInt),Vector.h(size()assert),Value.h(getMin/getMax)(std::min)(...)/(std::max)(...):StaticVector.h(x3),SmallVector.h,MultiPoolAllocator.hNo other
<windows.h>macro collisions turned up (small,interface,near/far,ERROR, etc.). The full-<windows.h>test below would catch any.Regression test (commit 2):
Tests/Windows/WindowsMinMaxTests.cpp, added to the NanoTest target only underif(WIN32). It explicitly#undefsNOMINMAX, includes full<windows.h>first, and#errors ifmaxisn't defined. It then includes the umbrella header plus every public header individually, and registersWindows.headers_compile_without_NOMINMAX, which usesValueWrapper<int>::getMin/getMaxandStaticVector::resize/getLastValidElementIndex.Validation
win(MSVC 14.51, x64, Ninja)rjob ... -VsDev -- cmake -S . -B build -G Ninja && cmake --build build, thenctest --test-dir build --output-on-failure -j16Windows.headers_compile_without_NOMINMAXwin, negative checkgit checkout 9f26b4a -- ea_data_structures(headers before the fix), rebuildWindowsMinMaxTests.cpp.objhits C4003 "not enough arguments for function-like macro invocation 'max'" plus syntax errors inVector.h:114,Span.h:75,StaticVector.h:170. After restoring the fixed headers it builds cleanlinux(Fedora Asahi aarch64, gcc)cmake -S . -B build -G Ninja && cmake --build build && ctest --test-dir build --output-on-failure -j8(tmux)studio(macOS, Apple clang)nice(tmux)The tests are pure unit tests with no windows or WebViews, so the win tests ran over
ssh win.Not verified
🤖 Generated with Claude Code