[clang-tools-extra] [clang-tidy] Add bugprone-smart-ptr-initialization check (PR #181570)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Aug 23 05:10:01 PDT 2026
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff origin/main HEAD --extensions cpp,h -- clang-tools-extra/clang-tidy/bugprone/SmartPtrInitializationCheck.cpp clang-tools-extra/clang-tidy/bugprone/SmartPtrInitializationCheck.h clang-tools-extra/test/clang-tidy/checkers/bugprone/smart-ptr-initialization-array-cxx17.cpp clang-tools-extra/test/clang-tidy/checkers/bugprone/smart-ptr-initialization-array.cpp clang-tools-extra/test/clang-tidy/checkers/bugprone/smart-ptr-initialization-cert-mem56-compliance.cpp clang-tools-extra/test/clang-tidy/checkers/bugprone/smart-ptr-initialization-declref.cpp clang-tools-extra/test/clang-tidy/checkers/bugprone/smart-ptr-initialization-macro.cpp clang-tools-extra/test/clang-tidy/checkers/bugprone/smart-ptr-initialization-parens.cpp clang-tools-extra/test/clang-tidy/checkers/bugprone/smart-ptr-initialization-ternary.cpp clang-tools-extra/test/clang-tidy/checkers/bugprone/smart-ptr-initialization.cpp clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp clang-tools-extra/clang-tidy/cert/CERTTidyModule.cpp --diff_from_common_commit
``````````
:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/clang-tools-extra/clang-tidy/bugprone/SmartPtrInitializationCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/SmartPtrInitializationCheck.cpp
index 76df33922..2c352f8ba 100644
--- a/clang-tools-extra/clang-tidy/bugprone/SmartPtrInitializationCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/SmartPtrInitializationCheck.cpp
@@ -82,23 +82,21 @@ void SmartPtrInitializationCheck::registerMatchers(MatchFinder *Finder) {
hasDeclaration(cxxConstructorDecl(ofClass(IsUniquePtrRecord)))));
// FIXME: need proper suppurt for conditionalOperator cases
- auto AllowedArguments =
- anyOf(ignoringParenCasts(cxxNewExpr()),
- ignoringParenCasts(ReleaseCallMatcher),
- ignoringParenCasts(conditionalOperator()));
+ auto AllowedArguments = anyOf(ignoringParenCasts(cxxNewExpr()),
+ ignoringParenCasts(ReleaseCallMatcher),
+ ignoringParenCasts(conditionalOperator()));
auto RawPtrMatcher =
- declRefExpr(to(varDecl(hasInitializer(ignoringParenCasts(cxxNewExpr()))).bind("raw-ptr")));
+ declRefExpr(to(varDecl(hasInitializer(ignoringParenCasts(cxxNewExpr())))
+ .bind("raw-ptr")));
auto SmartPtrConstructorMatcher = cxxConstructExpr(
hasDeclaration(
cxxConstructorDecl(ofClass(IsSmartPtrRecord.bind("method-parent")))
.bind("method-decl")),
hasArgument(0, PointerArg), unless(HasCustomDeleter),
- unless(hasArgument(
- 0, AllowedArguments)),
- optionally(hasArgument(
- 0, RawPtrMatcher)));
+ unless(hasArgument(0, AllowedArguments)),
+ optionally(hasArgument(0, RawPtrMatcher)));
// Matcher for reset() calls
// Exclude reset() calls with custom deleters:
@@ -119,10 +117,8 @@ void SmartPtrInitializationCheck::registerMatchers(MatchFinder *Finder) {
hasName("reset"))
.bind("method-decl")),
hasArgument(0, PointerArg), unless(HasCustomDeleterInReset),
- unless(hasArgument(
- 0, AllowedArguments)),
- optionally(hasArgument(
- 0, RawPtrMatcher)));
+ unless(hasArgument(0, AllowedArguments)),
+ optionally(hasArgument(0, RawPtrMatcher)));
Finder->addMatcher(SmartPtrConstructorMatcher, this);
Finder->addMatcher(ResetCallMatcher, this);
``````````
</details>
https://github.com/llvm/llvm-project/pull/181570
More information about the cfe-commits
mailing list