Repository navigation
hash: max and min in parentheses in every header, so a bare <windows.h> before them compiles - #20
Merged
Merged
Conversation
…dows.h> before them compiles A bare <windows.h> defines the macros min and max for the whole program. detail/limits.hpp's std::numeric_limits<std::size_t>::max() then stopped MSVC with C2589 in any program that included webcpp::hash's KDF headers after it: crypto's HPKE, which calls hkdf over pieces, met it in crypto's windows_h_before test on MSVC 14.3. Every header now writes (std::numeric_limits<T>::max)() and (std::min)(a, b), as crypto's do, and the test windows_h includes every public header after a bare <windows.h>, with every backend linked, and calls HKDF over spans and over pieces.
clang-tidy's readability-redundant-parentheses reports (std::numeric_limits<T>::max)(), the form the previous commit used against <windows.h>'s max macro. The <cstdint> and <climits> constants name the same values, and no macro expands them.
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.
A bare
<windows.h>(noNOMINMAX) defines the macrosminandmaxfor the whole program.detail/limits.hppwrotestd::numeric_limits<std::size_t>::max(), so any program that includes webcpp::hash's KDF headers after<windows.h>stops on MSVC with C2589. crypto's HPKE (webcpporg/crypto, branchcrypto/hpke) includeshash/hkdf.hpp, and crypto'swindows_h_beforetest hit this on MSVC 14.3 and 14.5 (it is the only test that puts<windows.h>first).include/now uses(std::min)(a, b), andSIZE_MAX,UINT64_MAXandULLONG_MAXin place ofstd::numeric_limits<T>::max(). No macro expands any of these, and clang-tidy'sreadability-redundant-parenthesesaccepts them, which it does not for(std::numeric_limits<T>::max)(). 10 headers changed, no behaviour change.windows_h: a bare<windows.h>, then every public header with OpenSSL, BearSSL and libsodium linked, then HKDF over spans and over pieces. It runs natively; off Windows it only compiles and calls.The changelog is unchanged: the code is unreleased, and the unreleased section is already at ten lines.
Verified locally:
windows_hpasses, and so do crypto'swindows_h_beforeand HPKE's tests built against it. Before the fix, crypto'swindows_h_beforefailed with C2589 atdetail/limits.hpp(45)and(63).windows_hpasses.This merges before crypto's HPKE. The superproject's gitlink of hash moves with the HPKE test vectors (webcpporg/webcpp branch
third_party/hpke-vectors).🤖 Generated with Claude Code