Repository navigation
Fix MSVC optimize pragma re-enable after keep_memory - #3212
Merged
horenmar merged 2 commits intoOct 6, 2026
Merged
Conversation
The keep_memory helper correctly disables MSVC optimizations with #if defined(_MSC_VER), but the matching pragma optimize on was guarded by the undefined _MSVC_VER macro. That left optimization disabled for the rest of any translation unit that included the benchmark headers, so measured code was compiled unoptimized on MSVC.
amedlin
force-pushed
the
fix/msvc-benchmark-optimize-pragma
branch
from
October 5, 2026 04:53
517c56b to
355ae22
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## devel #3212 +/- ##
==========================================
+ Coverage 91.14% 91.18% +0.03%
==========================================
Files 205 205
Lines 9100 9100
==========================================
+ Hits 8294 8297 +3
+ Misses 806 803 -3 🚀 New features to boost your workflow:
|
horenmar
reviewed
Oct 5, 2026
Reverted change, as PR review indication that amalgamated files should only change during release. Co-authored-by: Martin Hořeňovský <martin.horenovsky@gmail.com>
Member
|
Thanks |
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.
Description
On MSVC,
catch_optimizer.hppwrapskeep_memoryin#pragma optimize("", off)so the volatile self-assignment is not removed. The matching#pragma optimize("", on)was guarded by#if defined(_MSVC_VER), which is never defined (the correct macro is_MSC_VER).Because MSVC's
optimizepragma applies to subsequent functions in the translation unit, including any Catch2 benchmark header left the rest of that TU ? including user benchmark lambdas ? compiled with optimizations disabled. Timings then measured unoptimized code.This changes the re-enable guard to
_MSC_VERin bothcatch_optimizer.hppand the amalgamated header.GitHub Issues
Fixes #3211