Add CI guard against C++ alternative operator tokens - #128
Merged
Conversation
MSVC accepts the alternative operator tokens (and, or, not and friends) only when /permissive- is passed, which is not the default for a CMake-driven build. A single one of these in a widely included header therefore breaks the entire Windows build. Because the failure is a parse error, the cost is out of proportion to the cause. Two occurrences of 'and' in mesh.h (fixed in openmc-dev#4048) produced over a hundred cascade errors spread across unrelated translation units, including complaints about members of openmc::simulation and about MSVC's own internal _Cosh and _Exp names, none of which pointed at the actual line. clang-format does not rewrite these tokens, so nothing in CI catches them today. This adds a check that strips comments and string literals before scanning, so it does not trip on prose or on identifiers such as n_and and order. It reports file, line and the offending source line, and skips vendored code under src/external/. The script takes optional path arguments so it can be run directly during development: python tools/ci/check_alternative_tokens.py
12 tasks
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.
Why
MSVC accepts the C++ alternative operator tokens (
and,or,notand friends) only when/permissive-is passed, which is not the default for a CMake-driven build. One of these in a widely included header breaks the entire Windows build.The cost is badly out of proportion to the cause. Two occurrences of
andinmesh.h, fixed in openmc-dev#4048, produced over a hundred cascade errors in a Windows build probe, spread across unrelated translation units: missing members ofopenmc::simulation, undefinedUnstructuredMeshmembers, and complaints about MSVC's own internal_Coshand_Expnames. None of it pointed at the real line, which was the very first error in the log and easy to miss among the noise.clang-formatdoes not rewrite these tokens, so nothing in CI catches them today.What
tools/ci/check_alternative_tokens.py, which scanssrc/andinclude/and exits non-zero on any alternative operator token.alternative-tokensjob in the existingC++ Format Checkworkflow.The check strips comments and string literals before scanning, so it does not trip on prose. Newlines are preserved during stripping so reported line numbers match the original file. Vendored code under
src/external/is skipped.It reports file, line and the offending source line:
The script takes optional path arguments so it can be run locally during development:
Testing
developwith no findings, so it does not introduce a red CI.mesh.has of163fdf78^it flags exactly the two real sites at lines 636 and 701, matching the locations MSVC reported.#include <complex>, and the identifiersn_and,order,nothingandsword: no false positives, while genuineand,notandbitoroperators on adjacent lines are all caught.