Skip to content

clang-tidy: resolve bugprone-throwing-static-initialization#472

Merged
knoepfel merged 10 commits intomainfrom
maintenance/clang-tidy-fixes-2026-03-31
Apr 8, 2026
Merged

clang-tidy: resolve bugprone-throwing-static-initialization#472
knoepfel merged 10 commits intomainfrom
maintenance/clang-tidy-fixes-2026-03-31

Conversation

@greenc-FNAL
Copy link
Copy Markdown
Contributor

@greenc-FNAL greenc-FNAL commented Mar 30, 2026

Namespace-scope statics with non-trivial constructors (e.g. std::string, std::unordered_map) trigger bugprone-throwing-static-initialization because their constructors can throw before main(). The fix moves all such statics to function-local scope (guaranteed-lazy, exception-safe initialization).

Changes

  • phlex/core/detail/filter_impl.cpp — Wraps output_dummy and for_output_only_queries in a function returning product_queries const&. Also fixes a latent bug: the original return-by-value caused data_map::input_products_ to point to a destroyed temporary.

  • phlex/model/data_layer_hierarchy.cpp — Moves unnamed into maybe_name() as a static std::string const.

  • form/root_storage/root_tbranch_write_container.cpp — Moves typeNameToLeafList from namespace scope into setupWrite(). Map remains non-const with operator[] access: an unmapped fundamental type produces an empty leaf list, which ROOT silently treats as Float_t — this is intentional.

  • scripts/clang_tidy_fixes_to_problems.py — Fixes ruff I001/D101/D103 issues (import order, missing docstrings).

  • test/filter_impl.cpp — Adds "Data map for output only" test exercising data_map(for_output_t) to cover the new for_output_only() function.

  • test/data_cell_counting.cpp — Adds "Data layer hierarchy with unnamed layer" test; a child with an empty layer name triggers the maybe_name("") → "(unnamed)" path via the destructor's graph_layout() call.

@greenc-FNAL greenc-FNAL force-pushed the maintenance/clang-tidy-fixes-2026-03-31 branch from bbfe20c to 3c844a9 Compare March 30, 2026 20:34
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 30, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

@@            Coverage Diff             @@
##             main     #472      +/-   ##
==========================================
+ Coverage   85.49%   85.58%   +0.08%     
==========================================
  Files         142      142              
  Lines        3586     3601      +15     
  Branches      615      616       +1     
==========================================
+ Hits         3066     3082      +16     
+ Misses        311      310       -1     
  Partials      209      209              
Flag Coverage Δ
unittests 85.58% <100.00%> (+0.08%) ⬆️

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

Files with missing lines Coverage Δ
form/root_storage/root_tbranch_write_container.cpp 79.36% <100.00%> (+3.89%) ⬆️
phlex/core/detail/filter_impl.cpp 97.82% <100.00%> (+2.58%) ⬆️
phlex/model/data_layer_hierarchy.cpp 100.00% <100.00%> (+1.81%) ⬆️

... and 3 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 b1e67db...7b48c74. Read the comment docs.

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

@greenc-FNAL
Copy link
Copy Markdown
Contributor Author

@phlexbot tidy-fix -* bugprone-throwing-static-initialization

@github-actions
Copy link
Copy Markdown
Contributor

No automatic clang-tidy fixes were necessary.

@greenc-FNAL greenc-FNAL force-pushed the maintenance/clang-tidy-fixes-2026-03-31 branch from 07b2261 to fde2d7b Compare March 30, 2026 22:22
@greenc-FNAL
Copy link
Copy Markdown
Contributor Author

@phlexbot tidy-fix -* bugprone-throwing-static-initialization

@github-actions
Copy link
Copy Markdown
Contributor

No automatic clang-tidy fixes were necessary.

@greenc-FNAL greenc-FNAL force-pushed the maintenance/clang-tidy-fixes-2026-03-31 branch 3 times, most recently from 28c33b7 to 971666b Compare April 3, 2026 04:14
@greenc-FNAL
Copy link
Copy Markdown
Contributor Author

@greenc-FNAL greenc-FNAL force-pushed the maintenance/clang-tidy-fixes-2026-03-31 branch 6 times, most recently from a5dc634 to 1596018 Compare April 7, 2026 20:12
@greenc-FNAL greenc-FNAL changed the title [WIP] More clang-tidy fixes Resolve bugprone-throwing-static-initialization warnings from clang-tidy Apr 7, 2026
@greenc-FNAL greenc-FNAL marked this pull request as ready for review April 7, 2026 20:13
Copilot AI review requested due to automatic review settings April 7, 2026 20:13
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

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 addresses clang-tidy’s bugprone-throwing-static-initialization warnings by removing or deferring non-trivial static initialization in a few translation units and tests.

Changes:

  • Replaced inline std::string test constants with constexpr char const* and updated call sites to construct std::string where required.
  • Moved namespace-scope/static initializations to function-local statics (or fixtures) to avoid static initialization before main().
  • Refactored a ROOT leaf-list type mapping table from namespace scope into setupWrite().

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
test/form/test_utils.hpp Uses constexpr C-string literals for test file/tree names and adjusts string concatenation/calls accordingly.
test/data_cell_counting.cpp Defers _idq.hash initialization via a Catch2 fixture helper.
phlex/model/data_layer_hierarchy.cpp Reworks unnamed-layer formatting helper to avoid non-local static initialization.
phlex/core/detail/filter_impl.cpp Replaces namespace-scope statics with a helper function for output-only query defaults.
form/root_storage/root_tbranch_write_container.cpp Moves the type-to-leaf-list map into setupWrite() as a function-local static.

Comment thread phlex/core/detail/filter_impl.cpp Outdated
Comment thread test/data_cell_counting.cpp Outdated
Comment thread form/root_storage/root_tbranch_write_container.cpp
Copilot AI changed the title Resolve bugprone-throwing-static-initialization warnings from clang-tidy More clang-tidy fixes and ruff docstring/import cleanup Apr 7, 2026
@Framework-R-D Framework-R-D deleted a comment from Copilot AI Apr 7, 2026
@greenc-FNAL greenc-FNAL changed the title More clang-tidy fixes and ruff docstring/import cleanup Resolve bugprone-throwing-static-initialization warnings from clang-tidy Apr 7, 2026
@greenc-FNAL greenc-FNAL requested a review from Copilot April 7, 2026 20:33
greenc-FNAL added a commit that referenced this pull request Apr 7, 2026
@greenc-FNAL
Copy link
Copy Markdown
Contributor Author

@copilot Please add/augment tests as necessary to resolve the coverage gaps introduced by this PR as reported at https://github.com/Framework-R-D/phlex/pull/472/checks?check_run_id=70336551759

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 7, 2026

@copilot Please add/augment tests as necessary to resolve the coverage gaps introduced by this PR as reported at https://github.com/Framework-R-D/phlex/pull/472/checks?check_run_id=70336551759

Added two new tests in 2c39c2d:

  • "Data map for output only" in test/filter_impl.cpp — exercises data_map(for_output_t) to cover the new for_output_only() function (5 missing lines in phlex/core/detail/filter_impl.cpp).
  • "Data layer hierarchy with unnamed layer" in test/data_cell_counting.cpp — creates a child layer with an empty name, which triggers the maybe_name("")"(unnamed)" branch in phlex/model/data_layer_hierarchy.cpp (the 1 partial line) via the destructor's print()graph_layout()pretty_recurse() call chain.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • app.codecov.io
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node /home/REDACTED/work/_temp/ghcca-node/node/bin/node --enable-source-maps /home/REDACTED/work/_temp/copilot-developer-action-main/dist/index.js (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Comment thread test/data_cell_counting.cpp Outdated
@greenc-FNAL greenc-FNAL changed the title Resolve bugprone-throwing-static-initialization clang-tidy warnings clang-tidy: resolve bugprone-throwing-static-initialization Apr 8, 2026
Comment thread docs/dev/clang-tidy-fixes-2026-04.md
@greenc-FNAL greenc-FNAL force-pushed the maintenance/clang-tidy-fixes-2026-03-31 branch from 2d14746 to 4c607aa Compare April 8, 2026 13:54
greenc-FNAL added a commit that referenced this pull request Apr 8, 2026
greenc-FNAL added a commit that referenced this pull request Apr 8, 2026
@greenc-FNAL greenc-FNAL force-pushed the maintenance/clang-tidy-fixes-2026-03-31 branch from 4c607aa to 4b1ed51 Compare April 8, 2026 13:58
@greenc-FNAL greenc-FNAL force-pushed the maintenance/clang-tidy-fixes-2026-03-31 branch from 4b1ed51 to 7b48c74 Compare April 8, 2026 14:24
@greenc-FNAL greenc-FNAL requested a review from knoepfel April 8, 2026 14:33
@knoepfel knoepfel merged commit aaedaf5 into main Apr 8, 2026
36 checks passed
@knoepfel knoepfel deleted the maintenance/clang-tidy-fixes-2026-03-31 branch April 8, 2026 14:43
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.

4 participants