Skip to content

clang-tidy: resolve modernize-avoid-c-style-cast - #771

Merged
knoepfel merged 4 commits into
Framework-R-D:mainfrom
knoepfel:modernize-avoid-c-style-cast
Jul 30, 2026
Merged

clang-tidy: resolve modernize-avoid-c-style-cast#771
knoepfel merged 4 commits into
Framework-R-D:mainfrom
knoepfel:modernize-avoid-c-style-cast

Conversation

@knoepfel

@knoepfel knoepfel commented Jul 27, 2026

Copy link
Copy Markdown
Member

Resolve modernize-avoid-c-style-cast clang-tidy warnings.

  • Code quality: Replaced C-style casts with explicit static_cast expressions across resource usage, Python wrappers, and module argument handling to resolve modernize-avoid-c-style-cast clang-tidy warnings.
  • Tests: Updated product-selection and type-distinction test helpers to use safer, clearer type conversions.
  • Documentation: Marked the clang-tidy fix as complete and recorded the associated pull request reference.

knoepfel added a commit to knoepfel/phlex that referenced this pull request Jul 27, 2026
@coderabbitai

coderabbitai Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 74b33d42-4f22-411c-8b1b-fefc5621dd72

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

This change replaces C-style and functional casts with explicit static_cast or direct expressions across resource usage, Python bindings, and tests, and marks the corresponding clang-tidy checklist item complete.

Changes

Cast modernization

Layer / File(s) Summary
Python binding cast conversions
plugins/python/src/*.cpp
Python string lengths, scalar values, sentinel returns, index formatting, and concurrency initialization now use explicit C++ casts.
Runtime and test cast cleanup
phlex/utilities/resource_usage.cpp, test/*.cpp
Resource metrics and test provider conversions use explicit or direct expressions while preserving existing calculations.
Clang-tidy checklist update
docs/dev/clang-tidy-fixes-2026-04.md
The modernize-avoid-c-style-cast checklist entry is marked complete.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested reviewers: beojan, greenc-fnal

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 14.29% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ 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 matches the PR’s main change: fixing clang-tidy modernize-avoid-c-style-cast warnings.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@codecov

codecov Bot commented Jul 27, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.09677% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
plugins/python/src/modulewrap.cpp 69.23% 3 Missing and 1 partial ⚠️
@@            Coverage Diff             @@
##             main     #771      +/-   ##
==========================================
- Coverage   83.90%   83.83%   -0.08%     
==========================================
  Files         172      172              
  Lines        7231     7230       -1     
  Branches      850      850              
==========================================
- Hits         6067     6061       -6     
- Misses        883      888       +5     
  Partials      281      281              
Flag Coverage Δ
scripts 80.09% <ø> (ø)
unittests 85.69% <87.09%> (-0.11%) ⬇️

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

Files with missing lines Coverage Δ
form/root_storage/root_rfield_read_container.cpp 85.50% <100.00%> (ø)
form/storage/storage_reader.cpp 81.56% <100.00%> (-0.17%) ⬇️
phlex/utilities/resource_usage.cpp 100.00% <100.00%> (ø)
plugins/python/src/configwrap.cpp 75.80% <100.00%> (+0.19%) ⬆️
plugins/python/src/dciwrap.cpp 100.00% <100.00%> (ø)
plugins/python/src/dyncall.cpp 79.72% <100.00%> (ø)
plugins/python/src/pymodule.cpp 58.16% <100.00%> (ø)
plugins/python/src/modulewrap.cpp 75.35% <69.23%> (ø)

... and 2 files with indirect coverage changes


Continue to review full report in Codecov by Harness.

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

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

beojan
beojan previously approved these changes Jul 28, 2026
Comment thread plugins/python/src/modulewrap.cpp
Comment thread plugins/python/src/modulewrap.cpp
Comment thread plugins/python/src/modulewrap.cpp
knoepfel added a commit to knoepfel/phlex that referenced this pull request Jul 28, 2026
@knoepfel
knoepfel force-pushed the modernize-avoid-c-style-cast branch from f075f04 to 18551db Compare July 28, 2026 18:26

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/dev/clang-tidy-fixes-2026-04.md`:
- Around line 104-105: Reopen the modernize-avoid-c-style-cast checklist item
and address the remaining casts in configwrap.cpp and modulewrap.cpp by
converting each to an appropriate C++ cast; if any are intentionally retained,
add targeted per-location suppressions instead. Keep the checklist unresolved
until all remaining casts are handled.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 43248757-0555-4aa8-9193-23f1707fe8ca

📥 Commits

Reviewing files that changed from the base of the PR and between 93334dd and 18551db.

📒 Files selected for processing (7)
  • docs/dev/clang-tidy-fixes-2026-04.md
  • phlex/utilities/resource_usage.cpp
  • plugins/python/src/configwrap.cpp
  • plugins/python/src/dciwrap.cpp
  • plugins/python/src/modulewrap.cpp
  • test/product_selecting.cpp
  • test/type_distinction.cpp
📜 Review details
⏰ Context from checks skipped due to timeout. (4)
  • GitHub Check: Analyze cpp with CodeQL
  • GitHub Check: build (gcc, none)
  • GitHub Check: clang-tidy-check
  • GitHub Check: coverage
🧰 Additional context used
📓 Path-based instructions (4)
**/*.md

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

**/*.md: All Markdown files must follow markdownlint rule MD012: no multiple consecutive blank lines (never more than one blank line in a row)
All Markdown files must follow markdownlint rule MD022: headings must be surrounded by exactly one blank line before and after
All Markdown files must follow markdownlint rule MD031: fenced code blocks must be surrounded by exactly one blank line before and after
All Markdown files must follow markdownlint rule MD032: lists must be surrounded by exactly one blank line before and after (including after headings and code blocks)
All Markdown files must follow markdownlint rule MD034: no bare URLs (use markdown link syntax like [text](destination) instead of plain URLs)
All Markdown files must follow markdownlint rule MD036: use # headings for titles, not Bold:
All Markdown files must follow markdownlint rule MD040: always specify code block language (for example, use 'bash', 'python', '```text', etc.)

**/*.md: Do not use multiple consecutive blank lines in Markdown (MD012)
Surround Markdown headings with exactly one blank line (MD022)
Surround Markdown fenced code blocks with exactly one blank line (MD031)
Surround Markdown lists with exactly one blank line (MD032)
Do not use bare URLs in Markdown; use [text](url) syntax instead (MD034)
Use # headings in Markdown, not **Bold** for section titles (MD036)
Always specify language on fenced code blocks in Markdown (MD040)

Files:

  • docs/dev/clang-tidy-fixes-2026-04.md
**/*.{cpp,cc,cxx,h,hpp}

📄 CodeRabbit inference engine (.github/copilot-instructions.md)

**/*.{cpp,cc,cxx,h,hpp}: Use clang-format tool for all C++ code formatting (VS Code auto-formats on save); configuration defined in .clang-format with 100-character line limit and 2-space indentation
Follow clang-tidy recommendations defined in .clang-tidy

Files:

  • test/product_selecting.cpp
  • phlex/utilities/resource_usage.cpp
  • test/type_distinction.cpp
  • plugins/python/src/dciwrap.cpp
  • plugins/python/src/configwrap.cpp
  • plugins/python/src/modulewrap.cpp
**/*.{hpp,cpp}

📄 CodeRabbit inference engine (AGENTS.md)

**/*.{hpp,cpp}: Use .hpp for header files, .cpp for implementation, and *_test.cpp for test files in C++
Enforce 100-character line limit and 2-space indentation in C++ code via .clang-format
Use QualifierAlignment: Right (east-const) style: int const x not const int x in C++
Use PointerAlignment: Left in C++ (pointer * attached to type, not variable name)
All C++ identifiers must use lower_case naming: namespaces, classes, structs, enums, functions, variables, parameters, members, and constants
Exception to C++ naming: template parameters use CamelCase
Exception to C++ naming: macros use UPPER_CASE
Private, protected, and constant members in C++ must have a trailing underscore (_), no trailing underscore on anything else
Use enum class preferred over plain enum in C++
Use std::shared_ptr for shared ownership, std::unique_ptr for exclusive ownership, raw pointers for non-owning references only in C++
Use functors with agent-noun pattern: ModelEvaluator evaluate_model(...) in C++
Apply .clang-tidy checks for bugprone, cert, clang-analyzer, concurrency, cppcoreguidelines, misc, modernize, performance, portability, and readability as defined in the .clang-tidy configuration file
Use phlex:: namespace for core code, phlex::experimental:: for experimental features in C++

Files:

  • test/product_selecting.cpp
  • phlex/utilities/resource_usage.cpp
  • test/type_distinction.cpp
  • plugins/python/src/dciwrap.cpp
  • plugins/python/src/configwrap.cpp
  • plugins/python/src/modulewrap.cpp
plugins/python/**/*.cpp

📄 CodeRabbit inference engine (AGENTS.md)

plugins/python/**/*.cpp: Use std::runtime_error for C++ runtime failures; propagate Python exceptions via PyErr_SetString/PyErr_Format; return nullptr on error; call PyErr_Clear() when recovering in Python/C++ integration
Use manual Py_INCREF/Py_DECREF for reference counting and PyGILRAII RAII wrapper for GIL management in C++ code that interacts with Python
For GC-tracked Python types in C++: use Py_TPFLAGS_HAVE_GC, implement tp_traverse and tp_clear, call PyObject_GC_UnTrack before deallocation

Files:

  • plugins/python/src/dciwrap.cpp
  • plugins/python/src/configwrap.cpp
  • plugins/python/src/modulewrap.cpp
🔇 Additional comments (6)
plugins/python/src/configwrap.cpp (1)

145-146: LGTM!

Also applies to: 160-161, 174-174, 188-195

plugins/python/src/dciwrap.cpp (1)

30-30: LGTM!

plugins/python/src/modulewrap.cpp (1)

332-332: LGTM!

Also applies to: 500-502, 523-531, 549-552, 793-793, 1028-1028, 1174-1174

phlex/utilities/resource_usage.cpp (1)

29-31: LGTM!

test/product_selecting.cpp (1)

19-24: LGTM!

test/type_distinction.cpp (1)

27-27: LGTM!

Comment thread docs/dev/clang-tidy-fixes-2026-04.md
@knoepfel
knoepfel force-pushed the modernize-avoid-c-style-cast branch from 18551db to 875cd50 Compare July 28, 2026 18:57
@knoepfel
knoepfel force-pushed the modernize-avoid-c-style-cast branch from 3f97d5a to 7b2e8f3 Compare July 28, 2026 21:11
@knoepfel
knoepfel merged commit d64c9ba into Framework-R-D:main Jul 30, 2026
41 checks passed
@knoepfel
knoepfel deleted the modernize-avoid-c-style-cast branch July 30, 2026 16:05
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.

Clarify pylong_as_bool invalid-input return value

3 participants