Skip to content

clang-tidy: resolve cppcoreguidelines-owning-memory#551

Merged
knoepfel merged 15 commits into
mainfrom
maintenance/clang-tidy/cppcoreguidelines-owning-memory
May 6, 2026
Merged

clang-tidy: resolve cppcoreguidelines-owning-memory#551
knoepfel merged 15 commits into
mainfrom
maintenance/clang-tidy/cppcoreguidelines-owning-memory

Conversation

@greenc-FNAL
Copy link
Copy Markdown
Contributor

  • Follow C++ Core Guidelines for owning pointers when demangling symbols
  • Follow C++ Core Guidelines in test/form/reader.cpp
  • Avoid unnecessary (and likely problematic) new() in doRead()
  • Clarify and simplify getIndex() while avoiding raw delete
  • Qualify linkage as explicity PUBLIC
  • Avoid unnecessary (and likely problematic) new() operations
  • Use unique_ptr with a custom deleter for clarity and consistency
  • Follow C++ Core Guidelines for owning pointers

@greenc-FNAL greenc-FNAL force-pushed the maintenance/clang-tidy/cppcoreguidelines-owning-memory branch from 6741ab7 to aad1e77 Compare April 24, 2026 15:50
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 focuses on addressing clang-tidy’s cppcoreguidelines-owning-memory guidance by making ownership intent explicit and reducing raw new/delete usage across FORM ROOT storage, FORM tests, and the Python plugin bindings.

Changes:

  • Replaces ad-hoc raw-pointer ownership patterns with clearer ownership annotations (gsl::owner) and RAII (std::unique_ptr) in storage/test code paths.
  • Introduces a std::unique_ptr<TTree, Deleter> pattern for ROOT TTree lifetime handling in the write container.
  • Wires Microsoft.GSL into the relevant targets (FORM ROOT tests, ROOT storage, and Python plugin) to support gsl::owner usage.

Reviewed changes

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

Show a summary per file
File Description
test/form/test_utils.hpp Removes an unnecessary new PROD() in doRead() and reads into a raw pointer before wrapping in unique_ptr.
test/form/reader.cpp Annotates returned pointers as gsl::owner<...*> and links against GSL for ownership annotation support.
test/form/CMakeLists.txt Links Microsoft.GSL::GSL to the ReadVector test.
plugins/python/src/modulewrap.cpp Adds gsl::owner annotations for heap-allocated callback/provider functors (but allocations are still leaked).
plugins/python/CMakeLists.txt Links Microsoft.GSL::GSL into pymodule.
form/storage/storage_reader.cpp Replaces manual delete of read strings with std::unique_ptr to enforce RAII cleanup in getIndex().
form/storage/CMakeLists.txt Changes storage link visibility to PUBLIC for core and root_storage.
form/root_storage/root_ttree_write_container.hpp Switches m_tree to std::unique_ptr<TTree, TTreeDeleter> and documents ownership intent.
form/root_storage/root_ttree_write_container.cpp Implements TTreeDeleter and uses unique_ptr::reset() for TTree acquisition/creation.
form/root_storage/root_tbranch_read_container.cpp Avoids explicit allocations before SetBranchAddress() by passing a null pointer-to-pointer buffer.
form/root_storage/demangle_name.cpp Marks the demangled buffer as gsl::owner<char*> while still freeing with std::free().
form/root_storage/CMakeLists.txt Links Microsoft.GSL::GSL (PRIVATE) into root_storage.

Comment thread form/storage/CMakeLists.txt Outdated
Comment thread plugins/python/src/modulewrap.cpp Outdated
Comment thread plugins/python/src/modulewrap.cpp Outdated
Comment thread plugins/python/src/modulewrap.cpp Outdated
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 24, 2026

Codecov Report

❌ Patch coverage is 93.50649% with 5 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
form/root_storage/root_tbranch_read_container.cpp 91.83% 3 Missing and 1 partial ⚠️
form/root_storage/root_ttree_write_container.cpp 83.33% 0 Missing and 1 partial ⚠️
@@            Coverage Diff             @@
##             main     #551      +/-   ##
==========================================
+ Coverage   85.29%   85.39%   +0.09%     
==========================================
  Files         145      145              
  Lines        3679     3710      +31     
  Branches      632      646      +14     
==========================================
+ Hits         3138     3168      +30     
- Misses        324      329       +5     
+ Partials      217      213       -4     
Flag Coverage Δ
unittests 85.39% <93.50%> (+0.09%) ⬆️

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

Files with missing lines Coverage Δ
form/storage/storage_reader.cpp 81.81% <100.00%> (-0.80%) ⬇️
plugins/python/src/modulewrap.cpp 79.97% <100.00%> (-0.24%) ⬇️
form/root_storage/root_ttree_write_container.cpp 58.33% <83.33%> (+8.33%) ⬆️
form/root_storage/root_tbranch_read_container.cpp 91.39% <91.83%> (+12.55%) ⬆️

... and 4 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 fd89d58...dead99e. Read the comment docs.

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

Comment thread form/root_storage/root_tbranch_read_container.cpp Outdated
Comment thread form/root_storage/root_tbranch_read_container.cpp Outdated
Comment thread test/form/reader.cpp Outdated
Comment thread form/root_storage/root_ttree_write_container.hpp
Comment thread form/root_storage/root_ttree_write_container.hpp Outdated
Comment thread form/root_storage/root_ttree_write_container.hpp
Comment thread form/root_storage/root_tbranch_read_container.cpp Outdated
Comment thread form/root_storage/root_tbranch_read_container.cpp Outdated
Comment thread form/root_storage/root_ttree_write_container.cpp
@greenc-FNAL greenc-FNAL force-pushed the maintenance/clang-tidy/cppcoreguidelines-owning-memory branch 2 times, most recently from 595cc8b to e943cc3 Compare April 27, 2026 21:55
@greenc-FNAL greenc-FNAL force-pushed the maintenance/clang-tidy/cppcoreguidelines-owning-memory branch from e943cc3 to 6ba94eb Compare April 28, 2026 13:30
@greenc-FNAL greenc-FNAL force-pushed the maintenance/clang-tidy/cppcoreguidelines-owning-memory branch from 6ba94eb to d62d911 Compare April 28, 2026 19:59
@greenc-FNAL greenc-FNAL force-pushed the maintenance/clang-tidy/cppcoreguidelines-owning-memory branch 2 times, most recently from ffce55e to 0855059 Compare April 28, 2026 20:12
@greenc-FNAL greenc-FNAL force-pushed the maintenance/clang-tidy/cppcoreguidelines-owning-memory branch from 0855059 to daf7a96 Compare April 29, 2026 15:33
Comment thread form/root_storage/root_tbranch_read_container.cpp
Comment thread form/root_storage/root_tbranch_read_container.cpp
@greenc-FNAL greenc-FNAL force-pushed the maintenance/clang-tidy/cppcoreguidelines-owning-memory branch from daf7a96 to ee67040 Compare May 5, 2026 19:53
pcanal
pcanal previously approved these changes May 5, 2026
Copy link
Copy Markdown
Contributor

@pcanal pcanal left a comment

Choose a reason for hiding this comment

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

Looks good to me. If https://github.com/Framework-R-D/phlex/pull/551/changes#r3157633667 is not resolved in this PR, there ought to be an issue open to keep track of its resolution.

wwuoneway
wwuoneway previously approved these changes May 5, 2026
Copy link
Copy Markdown
Contributor

@wwuoneway wwuoneway left a comment

Choose a reason for hiding this comment

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

greenc-FNAL and others added 15 commits May 6, 2026 09:07
If non-ROOT allocation of memory is actually required, then the final
parameter to SetBranchAddress() should have been `false` (and we should
have sent `branchBuffer` instead of `&branchBuffer`). Otherwise, the
memory is allocated by ROOT anyway and memory may be leaked—or worse,
deallocated possibly inappropriately with `delete [] char`.
Be absolutely clear about the fact that we are managing the TTree's
memory ourselves to ensure that it is deleted at the right time, and
_after_ we ensure that pending objects have been written to the tree.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
- Interface library `form_test_utils` encapsulating header-specific
  dependency `ROOT::Core`
- Explicit dependence on `root_storage` instead of accidental via
  `storage`
- Improve coverage provided by `form_storage_test.cpp`
@greenc-FNAL greenc-FNAL dismissed stale reviews from wwuoneway and pcanal via dead99e May 6, 2026 14:12
@greenc-FNAL greenc-FNAL force-pushed the maintenance/clang-tidy/cppcoreguidelines-owning-memory branch from ee67040 to dead99e Compare May 6, 2026 14:12
@knoepfel knoepfel merged commit 1208c4f into main May 6, 2026
69 of 71 checks passed
@knoepfel knoepfel deleted the maintenance/clang-tidy/cppcoreguidelines-owning-memory branch May 6, 2026 16:00
knoepfel pushed a commit that referenced this pull request May 13, 2026
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.

6 participants