Skip to content

Replace raw #ifdef _MSC_VER with BOOST_CAPY_WORKAROUND macro#232

Merged
mvandeberg merged 1 commit intocppalliance:developfrom
mvandeberg:pr/144-workaround
Mar 12, 2026
Merged

Replace raw #ifdef _MSC_VER with BOOST_CAPY_WORKAROUND macro#232
mvandeberg merged 1 commit intocppalliance:developfrom
mvandeberg:pr/144-workaround

Conversation

@mvandeberg
Copy link
Contributor

@mvandeberg mvandeberg commented Mar 12, 2026

Closes #144

Add a standalone BOOST_CAPY_WORKAROUND(symbol, test) macro to detail/config.hpp, modeled on Boost.Config's BOOST_WORKAROUND. The guard mechanism evaluates to 0 when the compiler symbol is undefined, making workaround sites safe and self-documenting across compilers.

Also add BOOST_CAPY_MSVC_WARNING_PUSH/DISABLE/POP helpers that use __pragma() on MSVC and expand to nothing elsewhere, replacing the repetitive 4-line #ifdef/#pragma/#endif sandwich pattern.

Feature-detection sites (_MSC_VER for TLS keyword, __forceinline, RTTI, FUNCSIG) are intentionally left as raw checks since they are not bug workarounds.

Summary by CodeRabbit

  • Chores
    • Consolidated compiler warning handling into project-wide macros and introduced a unified compiler workaround mechanism for improved consistency and portability; no functional or public API changes.

@coderabbitai
Copy link

coderabbitai bot commented Mar 12, 2026

📝 Walkthrough

Walkthrough

This PR centralizes compiler workarounds by introducing BOOST_CAPY_WORKAROUND and MSVC warning control macros, and replaces scattered MSVC-specific #ifdef/#pragma blocks across headers and sources with those macros. No public APIs or runtime logic are changed.

Changes

Cohort / File(s) Summary
Config / macros
include/boost/capy/detail/config.hpp
Add BOOST_CAPY_WORKAROUND(...) and MSVC warning control macros BOOST_CAPY_MSVC_WARNING_PUSH, BOOST_CAPY_MSVC_WARNING_DISABLE(x), BOOST_CAPY_MSVC_WARNING_POP plus related guard macros.
MSVC warning replacements — headers
include/boost/capy/buffers/make_buffer.hpp, include/boost/capy/delay.hpp, include/boost/capy/ex/async_event.hpp, include/boost/capy/ex/async_mutex.hpp, include/boost/capy/ex/detail/timer_service.hpp, include/boost/capy/ex/recycling_memory_resource.hpp
Replace per-file #ifdef _MSC_VER / #pragma warning(...) blocks with project macros around aligned storage and class/member declarations. No behavior changes.
Workaround conditional replacements
include/boost/capy/detail/await_suspend_helper.hpp, include/boost/capy/io_result.hpp
Switch #ifdef _MSC_VER or MSVC-version guards to #if BOOST_CAPY_WORKAROUND(_MSC_VER, ...) to select MSVC-specific branches.
MSVC warning replacements — execution / internals
include/boost/capy/ex/execution_context.hpp
Replace MSVC pragma blocks around private members (type_index, mutex, etc.) with the new MSVC warning macros.
MSVC warning replacements — sources
src/cond.cpp, src/error.cpp
Replace MSVC-versioned #if defined(_MSC_VER) && ... pragma sequences with #if BOOST_CAPY_WORKAROUND(_MSC_VER, ...) and the MSVC warning macros around constinit/global declarations.
Small header replacement
include/boost/capy/buffers/make_buffer.hpp
Replaced MSVC pragma push/disable/pop with BOOST_CAPY_MSVC_WARNING_* macros (aligned-storage warning suppression).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

Suggested reviewers

  • sgerbino

Poem

🐰
I hopped through code, replaced the maze,
Pragmas swapped for tidy ways.
Workarounds grouped, warnings tamed,
Builds stay steady, flags renamed. 🥕

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and specifically identifies the main change: replacing raw #ifdef _MSC_VER checks with the BOOST_CAPY_WORKAROUND macro across the codebase.
Linked Issues check ✅ Passed The PR fully satisfies issue #144 requirements: BOOST_CAPY_WORKAROUND macro created, MSVC warning control helper macros added, and bug-workaround sites systematically replaced while preserving feature-detection checks.
Out of Scope Changes check ✅ Passed All changes are directly scoped to issue #144: macro definitions in config.hpp and their usage replacing raw #ifdef _MSC_VER patterns. No unrelated modifications detected.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
📝 Coding Plan
  • Generate coding plan for human review comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@cppalliance-bot
Copy link

cppalliance-bot commented Mar 12, 2026

An automated preview of the documentation is available at https://232.capy.prtest3.cppalliance.org/index.html

If more commits are pushed to the pull request, the docs will rebuild at the same URL.

2026-03-12 20:01:51 UTC

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
include/boost/capy/ex/execution_context.hpp (1)

526-531: Minor: Comment placement appears after the macro.

The explanatory comment on line 528 is placed between BOOST_CAPY_MSVC_WARNING_DISABLE(4251) and the affected members. This differs from lines 165-170 and 504-506 where the comment precedes the PUSH macro. Consider moving the comment before BOOST_CAPY_MSVC_WARNING_PUSH for consistency with the other regions in this file.

Suggested fix for comment placement consistency
+// warning C4251: std::mutex, std::shared_ptr need dll-interface
     BOOST_CAPY_MSVC_WARNING_PUSH
     BOOST_CAPY_MSVC_WARNING_DISABLE(4251)
-// warning C4251: std::mutex, std::shared_ptr need dll-interface
     mutable std::mutex mutex_;
     std::shared_ptr<void> owned_;
     BOOST_CAPY_MSVC_WARNING_POP
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@include/boost/capy/ex/execution_context.hpp` around lines 526 - 531, Move the
explanatory comment about warning C4251 so it precedes
BOOST_CAPY_MSVC_WARNING_PUSH for consistency with other regions; specifically,
relocate the comment that currently sits between
BOOST_CAPY_MSVC_WARNING_DISABLE(4251) and the member declarations so it appears
before BOOST_CAPY_MSVC_WARNING_PUSH that wraps the declarations of mutable
std::mutex mutex_ and std::shared_ptr<void> owned_.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@include/boost/capy/detail/config.hpp`:
- Around line 24-56: Remove the three _WORKAROUND_GUARD helper macros
(_MSC_VER_WORKAROUND_GUARD, __GNUC___WORKAROUND_GUARD,
__clang_major___WORKAROUND_GUARD) and simplify BOOST_CAPY_WORKAROUND to test the
compiler symbol directly (use the symbol in the boolean and modulus expression)
since undefined preprocessor identifiers evaluate as 0 in `#if` contexts; update
the macro BOOST_CAPY_WORKAROUND(symbol, test) to use (symbol) directly (e.g.
check (symbol != 0) and the 1 % (((symbol) test) + 1) expression) and remove any
references to the removed guard macros (search for BOOST_CAPY_WORKAROUND and the
three guard macro names to locate all occurrences).

---

Nitpick comments:
In `@include/boost/capy/ex/execution_context.hpp`:
- Around line 526-531: Move the explanatory comment about warning C4251 so it
precedes BOOST_CAPY_MSVC_WARNING_PUSH for consistency with other regions;
specifically, relocate the comment that currently sits between
BOOST_CAPY_MSVC_WARNING_DISABLE(4251) and the member declarations so it appears
before BOOST_CAPY_MSVC_WARNING_PUSH that wraps the declarations of mutable
std::mutex mutex_ and std::shared_ptr<void> owned_.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 56af68d2-c436-40ce-ab39-81ba100b6511

📥 Commits

Reviewing files that changed from the base of the PR and between 19821af and 50fbbed.

⛔ Files ignored due to path filters (1)
  • test/unit/test_helpers.hpp is excluded by !**/test/**
📒 Files selected for processing (12)
  • include/boost/capy/buffers/make_buffer.hpp
  • include/boost/capy/delay.hpp
  • include/boost/capy/detail/await_suspend_helper.hpp
  • include/boost/capy/detail/config.hpp
  • include/boost/capy/ex/async_event.hpp
  • include/boost/capy/ex/async_mutex.hpp
  • include/boost/capy/ex/detail/timer_service.hpp
  • include/boost/capy/ex/execution_context.hpp
  • include/boost/capy/ex/recycling_memory_resource.hpp
  • include/boost/capy/io_result.hpp
  • src/cond.cpp
  • src/error.cpp

@cppalliance-bot
Copy link

cppalliance-bot commented Mar 12, 2026

GCOVR code coverage report https://232.capy.prtest3.cppalliance.org/gcovr/index.html
LCOV code coverage report https://232.capy.prtest3.cppalliance.org/genhtml/index.html
Coverage Diff Report https://232.capy.prtest3.cppalliance.org/diff-report/index.html

Build time: 2026-03-12 20:16:35 UTC

@codecov
Copy link

codecov bot commented Mar 12, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.48%. Comparing base (ecdb076) to head (ed8bb80).
⚠️ Report is 2 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #232      +/-   ##
===========================================
+ Coverage    92.39%   92.48%   +0.08%     
===========================================
  Files          162      162              
  Lines         8866     8958      +92     
===========================================
+ Hits          8192     8285      +93     
+ Misses         674      673       -1     
Flag Coverage Δ
linux 92.44% <ø> (+0.05%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
include/boost/capy/buffers/make_buffer.hpp 100.00% <ø> (ø)
include/boost/capy/delay.hpp 100.00% <ø> (ø)
include/boost/capy/detail/await_suspend_helper.hpp 66.66% <ø> (ø)
include/boost/capy/ex/async_event.hpp 100.00% <ø> (ø)
include/boost/capy/ex/async_mutex.hpp 98.93% <ø> (ø)
include/boost/capy/ex/detail/timer_service.hpp 100.00% <ø> (ø)
include/boost/capy/ex/execution_context.hpp 98.07% <ø> (ø)
...nclude/boost/capy/ex/recycling_memory_resource.hpp 80.39% <ø> (ø)
src/cond.cpp 72.41% <ø> (ø)
src/error.cpp 58.33% <ø> (ø)

... and 11 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ecdb076...ed8bb80. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

…ance#144)

Add a standalone BOOST_CAPY_WORKAROUND(symbol, test) macro to
detail/config.hpp, modeled on Boost.Config's BOOST_WORKAROUND. The
guard mechanism evaluates to 0 when the compiler symbol is undefined,
making workaround sites safe and self-documenting across compilers.

Also add BOOST_CAPY_MSVC_WARNING_PUSH/DISABLE/POP helpers that use
__pragma() on MSVC and expand to nothing elsewhere, replacing the
repetitive 4-line #ifdef/#pragma/#endif sandwich pattern.

Feature-detection sites (_MSC_VER for TLS keyword, __forceinline,
RTTI, __FUNCSIG__) are intentionally left as raw checks since they
are not bug workarounds.
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
include/boost/capy/detail/await_suspend_helper.hpp (1)

54-54: Include detail/config.hpp directly in this header.

This condition now depends on BOOST_CAPY_WORKAROUND, but the header only includes boost/capy/ex/io_env.hpp. Relying on a transitive include makes the header brittle and can turn a future include cleanup into a preprocessing error.

♻️ Proposed fix
 `#include` <coroutine>
+#include <boost/capy/detail/config.hpp>
 `#include` <boost/capy/ex/io_env.hpp>
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@include/boost/capy/detail/await_suspend_helper.hpp` at line 54, This header
uses the BOOST_CAPY_WORKAROUND macro but only includes boost/capy/ex/io_env.hpp
(relying on a transitive include); update await_suspend_helper.hpp to directly
include detail/config.hpp so BOOST_CAPY_WORKAROUND is available; locate the top
of the file near the existing include of boost/capy/ex/io_env.hpp and add a
direct include for detail/config.hpp (ensuring the include uses the same
relative path pattern as other headers in this directory).
include/boost/capy/detail/config.hpp (1)

18-22: Drop the divider banner here.

The new dashed block adds noise in a short header and conflicts with the repo rule to keep ASCII art to a minimum.

As per coding guidelines, "Keep the ascii-art to a minimum, only add dividers if the class declaration is very long."

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@include/boost/capy/detail/config.hpp` around lines 18 - 22, Remove the
ASCII-art divider lines around the "Compiler bug workarounds" header: replace
the two "//------------------------------------------------" lines and the
surrounding blank lines with a single simple comment like "// Compiler bug
workarounds" so only a minimal, non-decorative header remains; update the block
containing the existing "//------------------------------------------------"
markers and the "Compiler bug workarounds" text in config.hpp (i.e., the
commented divider around that section) accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@include/boost/capy/detail/await_suspend_helper.hpp`:
- Line 54: This header uses the BOOST_CAPY_WORKAROUND macro but only includes
boost/capy/ex/io_env.hpp (relying on a transitive include); update
await_suspend_helper.hpp to directly include detail/config.hpp so
BOOST_CAPY_WORKAROUND is available; locate the top of the file near the existing
include of boost/capy/ex/io_env.hpp and add a direct include for
detail/config.hpp (ensuring the include uses the same relative path pattern as
other headers in this directory).

In `@include/boost/capy/detail/config.hpp`:
- Around line 18-22: Remove the ASCII-art divider lines around the "Compiler bug
workarounds" header: replace the two
"//------------------------------------------------" lines and the surrounding
blank lines with a single simple comment like "// Compiler bug workarounds" so
only a minimal, non-decorative header remains; update the block containing the
existing "//------------------------------------------------" markers and the
"Compiler bug workarounds" text in config.hpp (i.e., the commented divider
around that section) accordingly.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 4c2c5c75-bfc2-4696-8208-4fe652214cb2

📥 Commits

Reviewing files that changed from the base of the PR and between 50fbbed and ed8bb80.

⛔ Files ignored due to path filters (1)
  • test/unit/test_helpers.hpp is excluded by !**/test/**
📒 Files selected for processing (12)
  • include/boost/capy/buffers/make_buffer.hpp
  • include/boost/capy/delay.hpp
  • include/boost/capy/detail/await_suspend_helper.hpp
  • include/boost/capy/detail/config.hpp
  • include/boost/capy/ex/async_event.hpp
  • include/boost/capy/ex/async_mutex.hpp
  • include/boost/capy/ex/detail/timer_service.hpp
  • include/boost/capy/ex/execution_context.hpp
  • include/boost/capy/ex/recycling_memory_resource.hpp
  • include/boost/capy/io_result.hpp
  • src/cond.cpp
  • src/error.cpp
🚧 Files skipped from review as they are similar to previous changes (2)
  • include/boost/capy/buffers/make_buffer.hpp
  • include/boost/capy/delay.hpp

@mvandeberg mvandeberg merged commit 5d9fa36 into cppalliance:develop Mar 12, 2026
39 checks passed
@mvandeberg mvandeberg deleted the pr/144-workaround branch March 12, 2026 22:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Down with #ifdef _MSC_VER

2 participants