Skip to content

[beman-tidy] Implement cpp.no_flag_forking check - #342

Draft
neatudarius wants to merge 5 commits into
bemanproject:mainfrom
neatudarius:implement/issue-61-cpp-no-flag-forking
Draft

neatudarius wants to merge 5 commits into
bemanproject:mainfrom
neatudarius:implement/issue-61-cpp-no-flag-forking

Conversation

@neatudarius

@neatudarius neatudarius commented Jul 15, 2026 •

Copy link
Copy Markdown
Member

Implements #61

@neatudarius neatudarius changed the title Implement cpp.no_flag_forking check [beman-tidy] Implement cpp.no_flag_forking check Jul 15, 2026
@neatudarius
neatudarius force-pushed the implement/issue-61-cpp-no-flag-forking branch 4 times, most recently from bca53fa to 8689a2f Compare July 15, 2026 23:53
@neatudarius
neatudarius requested a review from Copilot July 16, 2026 00:02

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds a new beman-standard C++ check (cpp.no_flag_forking) intended to detect direct use of __cpp_* feature-test macros in preprocessor conditionals, plus test fixtures validating the check’s pass/fail behavior.

Changes:

  • Implement CppNoFlagForkingCheck with a per-file scan that logs and fails on matched __cpp_* usage.
  • Add new test cases and C++ fixture files covering valid (config-macro-based) and invalid (__cpp_*-based) examples.
  • Wire the new check into the existing C++ beman-standard checks module and test suite imports.

Reviewed changes

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

File Description
beman_tidy/lib/checks/beman_standard/cpp.py Introduces cpp.no_flag_forking check implementation and supporting utilities usage.
tests/lib/checks/beman_standard/cpp/test_cpp.py Adds unit tests for cpp.no_flag_forking (valid/invalid) and a skipped fix-inplace placeholder.
tests/lib/checks/beman_standard/cpp/no_flag_forking/valid/uses_config.hpp Valid fixture using config.hpp macro instead of __cpp_*.
tests/lib/checks/beman_standard/cpp/no_flag_forking/invalid/uses_feature_test_macro.hpp Invalid fixture using __cpp_* feature-test macros in #if/#elif.

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

@neatudarius
neatudarius force-pushed the implement/issue-61-cpp-no-flag-forking branch 6 times, most recently from 0242116 to 2637df1 Compare July 16, 2026 06:38
@neatudarius
neatudarius force-pushed the implement/issue-61-cpp-no-flag-forking branch from 2637df1 to b2571b5 Compare July 16, 2026 06:43
…p-no-flag-forking

# Conflicts:
#	beman_tidy/lib/checks/beman_standard/cpp.py
#	tests/lib/checks/beman_standard/cpp/test_cpp.py
Cover #ifdef/#ifndef, compound and continued conditions, ignore comments,
and exempt the library's own include/beman/<lib>/config.hpp fallback.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

The check skips config.hpp and mishandles raw strings, line splicing, and block comments, allowing prohibited feature-test probes to pass while incorrectly flagging harmless text.

4 open issues
2 resolved since last review

Review effort: Balanced

directive = lines[line_index].rstrip("\n")
while directive.rstrip().endswith("\\") and line_index + 1 < len(lines):
line_index += 1
directive = directive.rstrip()[:-1] + " " + lines[line_index].rstrip("\n")
Comment on lines +162 to +163
if not outer._CONDITIONAL_DIRECTIVE_RE.match(directive):
continue
Comment on lines +162 to +168
if not outer._CONDITIONAL_DIRECTIVE_RE.match(directive):
continue
if determine_comment_type(lines, start_index) is not None:
continue

directive = outer._BLOCK_COMMENT_RE.sub(" ", directive)
directive = outer._LINE_COMMENT_RE.sub("", directive)
Comment on lines +175 to +176
if self._is_config_header():
return True
…king

Assert exact violation lines per case and the per-library config.hpp exemption.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants