Skip to content

Fix Windows build compatibility (MSVC cl.exe and clang-cl)#99

Merged
wavefunction91 merged 15 commits into
wavefunction91:masterfrom
lorisercole:fix/msvc-build
Jun 11, 2026
Merged

Fix Windows build compatibility (MSVC cl.exe and clang-cl)#99
wavefunction91 merged 15 commits into
wavefunction91:masterfrom
lorisercole:fix/msvc-build

Conversation

@lorisercole

@lorisercole lorisercole commented May 7, 2026

Copy link
Copy Markdown
Contributor

Summary

Enable IntegratorXX to build and test cleanly with both MSVC cl.exe and clang-cl on Windows.

Compiler compatibility fixes

  • Fix MSVC C1061 'blocks nested too deeply' in womersley.hpp: split 125-branch if-else dispatch into two halves; replace another with a 3-line clamp
  • Replace C++ alternative operator tokens (and, or, not) with &&, ||, ! across 11 headers (MSVC requires /permissive- otherwise)
  • Add _USE_MATH_DEFINES for M_PI and /bigobj for large test translation units

MSVC warning fixes (all fixed at source)

  • C4242/C4244: ::toupper returns int — use explicit unsigned char cast lambda in std::transform; explicit static_cast for size_tpoint_type in Gauss-Legendre/Gauss-Lobatto and factorial→double in SphericalHarmonic
  • C4267: size_tint narrowing — use int in ref_value lambdas; cast size_t to ptrdiff_t in spherical_micro_batcher::at(); cast for custom iterator::operator+(int)
  • C4530: add /EHsc to IntegratorXX and FetchContent'd Catch2 targets

clang-cl warning fixes

  • Suppress -Wno-unused-but-set-variable and -Wno-suggest-override
  • Fix -Wno-missing-braces scope: was INTERFACE (consumers only), now matches INTEGRATORXX_TARGET_TYPE so compiled library sources also receive it

Other

  • Add missing #include <numeric> in composite quadratures test
  • Cast loop index to size_t in quadrature_traits to avoid downstream C4267 in GauXC

MSVC has a hard limit of ~128 nesting levels for if-else chains.
The Womersley quadrature traits had two functions exceeding this:

- generate(): ~125-branch if-else dispatch. Split into two halves
  by extracting npts >= 2049 into a generate_large_npts_() helper,
  keeping each half under 64 branches.

- next_algebraic_order(): ~125-branch if-else that simply returned
  the input clamped to [1, 125]. Replaced with a 3-line equivalent.
MSVC does not support C++ alternative operator tokens (and, or, not)
without /permissive-. Replace with standard &&, ||, ! across all
headers (11 files).

Also add MSVC-specific flags to CMakeLists.txt:
- _USE_MATH_DEFINES: needed for M_PI in MSVC CRT
- /bigobj: test TUs exceed default COFF section limit
The flag was hardcoded as INTERFACE, which only propagates to consumers.
When IntegratorXX builds as a compiled library (INTEGRATORXX_HEADER_ONLY=OFF),
its own sources never received the suppression. Use INTEGRATORXX_TARGET_TYPE
(PUBLIC or INTERFACE) so it matches the other target_compile_options calls.

GCC hides this because it removed -Wmissing-braces from -Wall in GCC 4.8;
Clang still enables it, causing thousands of warnings on clang-cl builds.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR improves Windows build compatibility (MSVC cl.exe and clang-cl) by reducing MSVC parser limits in large dispatch code paths, avoiding C++ alternative operator tokens, and adjusting CMake compile options/definitions to apply correctly for both header-only and compiled-library builds.

Changes:

  • Refactors the large Womersley npts dispatch and simplifies next_algebraic_order to avoid MSVC C1061 nesting limits.
  • Replaces alternative operator tokens (and, or, not) with &&, ||, ! across multiple headers for MSVC compatibility.
  • Updates CMake to apply warning suppressions correctly and adds MSVC-specific flags/definitions; adds a missing <numeric> include to a test TU.

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
CMakeLists.txt Applies -Wno-missing-braces with the correct target scope; adds MSVC/clang-cl-specific flags/defs.
test/composite_quadratures.cxx Adds missing <numeric> include for algorithms used in the test.
include/integratorxx/util/bound_transform.hpp Replaces alternative tokens with standard logical operators.
include/integratorxx/quadratures/s2/womersley.hpp Splits large if/else dispatch and clamps next_algebraic_order to avoid MSVC nesting-depth limits.
include/integratorxx/quadratures/radial/treutlerahlrichs.hpp Replaces alternative tokens with &&.
include/integratorxx/quadratures/radial/muraknowles.hpp Replaces alternative tokens with &&.
include/integratorxx/quadratures/radial/mhl.hpp Replaces alternative tokens with &&.
include/integratorxx/quadratures/radial/becke.hpp Replaces alternative tokens with &&.
include/integratorxx/quadratures/primitive/gausslobatto.hpp Replaces not with ! in convergence check.
include/integratorxx/quadratures/primitive/gausslegendre.hpp Replaces not with ! in convergence check.
include/integratorxx/quadrature.hpp Replaces and with && in SFINAE constraints.
include/integratorxx/generators/spherical_factory.hpp Replaces alternative tokens with && in equality operators.
include/integratorxx/composite_quadratures/pruned_spherical_quadrature.hpp Replaces alternative tokens with && / ! in iterator comparisons.
include/integratorxx/batch/spherical_micro_batcher.hpp Replaces alternative tokens with `

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread include/integratorxx/generators/spherical_factory.hpp
Comment thread include/integratorxx/batch/spherical_micro_batcher.hpp
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@lorisercole

lorisercole commented Jun 5, 2026

Copy link
Copy Markdown
Contributor Author

Just adapted the build with MSVC cl and clang-cl to comply with Microsoft 1CS corporate policies.

-DCMAKE_CXX_FLAGS="/W3 /w14018 /w14055 /w14100 /w14102 /w14127 /w14146 /w14242 /w14244 /w14245 /w14254 /w14267 /w14302 /w14306 /w14308 /w14310 /w14389 /w14509 /w14510 /w14512 /w14532 /w14533 /w14610 /w14611 /w14700 /w14701 /w14703 /w14789 /w14995 /w14996" `
-DCMAKE_CXX_FLAGS_RELEASE="/O2 /DNDEBUG" `

+ same for C flags

@wavefunction91 wavefunction91 merged commit 619d26a into wavefunction91:master Jun 11, 2026
8 checks passed
@lorisercole lorisercole deleted the fix/msvc-build branch June 12, 2026 08:29
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.

3 participants