Skip to content

fix(lint-configs): Suppress clang-tidy copy warnings for std::shared_ptr as the copy is necessary for reference counting.#115

Open
davidlion wants to merge 1 commit into
y-scope:mainfrom
davidlion:shared_ptr
Open

fix(lint-configs): Suppress clang-tidy copy warnings for std::shared_ptr as the copy is necessary for reference counting.#115
davidlion wants to merge 1 commit into
y-scope:mainfrom
davidlion:shared_ptr

Conversation

@davidlion

@davidlion davidlion commented Jun 26, 2026

Copy link
Copy Markdown
Member

Description

The clang-tidy checks unnecessary-copy-initialization and unnecessary-value-param help devs to avoid unnecessary copies by pointing out when it is possible to use const&. This is great most of the time, but these checks will also flag reference counting types.

In our code this issue manifests primarily with std::shared_ptr function parameters. When the shared pointer would be copy constructed the reference count would be increased, however if the dev switches to std::shared_ptr const& there will be no reference counting as there is no construction. It is technically safe to do this as long as the object being referenced is guaranteed to not fall out of scope while the reference is held, but it is much easier to reason about reference counted types when they always perform the counting.
If performing these copies is ever a serious performance concern we should probably be investigating how to not use shared_ptrs entirely than skipping the copy.

There are other referencing counting stdlib types that this applies to, but I think we can add them on a case-by-case basis.

https://clang.llvm.org/extra/clang-tidy/checks/performance/unnecessary-copy-initialization.html
https://clang.llvm.org/extra/clang-tidy/checks/performance/unnecessary-value-param.html
llvm/llvm-project#153247

Checklist

  • The PR satisfies the contribution guidelines.
  • This is a breaking change and that has been indicated in the PR title, OR this isn't a
    breaking change.
  • Necessary docs have been updated, OR no docs need to be updated.

Validation performed

I've been building y-scope/clp/main and davidlion/clp/clpp with these changes.

Summary by CodeRabbit

  • Chores
    • Updated linting configuration to better handle reference-counted types in performance checks.
    • Allowed shared pointers in additional performance-related checks, with clearer guidance in the configuration comments.
    • Improved nearby comment punctuation for consistency.

@davidlion davidlion requested a review from a team as a code owner June 26, 2026 02:07
@coderabbitai

coderabbitai Bot commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

The .clang-tidy config was updated to add std::shared_ptr allowlists for two performance checks and to adjust the surrounding comment text.

Changes

Lint configuration update

Layer / File(s) Summary
Shared_ptr allowances
exports/lint-configs/.clang-tidy
The existing public-member rule entry remains, its comment text is updated, and std::shared_ptr is allowed for performance-unnecessary-copy-initialization and performance-unnecessary-value-param.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~2 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
Title check ✅ Passed The title accurately describes the lint-config change to allow std::shared_ptr copies for clang-tidy warnings because reference counting requires the copy.
✨ 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.

@davidlion davidlion changed the title feat(lint-configs): Exclude std::shared_ptr from clang-tidy unnecessary copy checks as skipping the copy will skip the reference counting. fix(lint-configs): Suppress clang-tidy copy warnings for std::shared_ptr as the copy is necessary for reference counting. Jun 26, 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.

1 participant