PiotrZSL created this revision.
PiotrZSL added reviewers: njames93, carlosgalvezp.
Herald added a subscriber: xazax.hun.
Herald added a project: All.
PiotrZSL requested review of this revision.
Herald added a project: clang-tools-extra.
Herald added a subscriber: cfe-commits.
Implicit code like, template instances, compiler generated
code are not excluded in this check by using
TK_IgnoreUnlessSpelledInSource.
Fixes #62693
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D151133
Files:
clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.h
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/test/clang-tidy/checkers/bugprone/branch-clone.cpp
Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/branch-clone.cpp
===================================================================
--- clang-tools-extra/test/clang-tidy/checkers/bugprone/branch-clone.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/branch-clone.cpp
@@ -1024,3 +1024,37 @@
SEMICOLON_CASE_COLON(3);
}
}
+
+namespace PR62693 {
+ class Object {
+ public:
+ template <typename T>
+ bool ConvertableTo() const;
+
+ template <typename T>
+ void Handle();
+ };
+
+ template <typename T>
+ void update(Object &a) {
+ if (a.ConvertableTo<char *>()) {
+ a.Handle<char *>();
+ } else {
+ a.Handle<T>();
+ }
+ }
+
+ template <typename T>
+ void update2(Object &a) {
+ if (a.ConvertableTo<char *>()) {
+ a.Handle<char *>();
+ } else {
+ a.Handle<T>();
+ }
+ }
+
+ void foo(Object &a) {
+ update<int>(a);
+ update2<char *>(a);
+ }
+}
Index: clang-tools-extra/docs/ReleaseNotes.rst
===================================================================
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -201,6 +201,11 @@
Changes in existing checks
^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+- Fixed false-positive in :doc:`bugprone-branch-clone
+ <clang-tidy/checks/bugprone/branch-clone>` check by ignoring auto-generated
+ code, template instances, and implicit code patterns.
+
- Improved :doc:`readability-redundant-string-cstr
<clang-tidy/checks/readability/redundant-string-cstr>` check to recognise
unnecessary ``std::string::c_str()`` and ``std::string::data()`` calls in
Index: clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.h
===================================================================
--- clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.h
+++ clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.h
@@ -27,6 +27,9 @@
: ClangTidyCheck(Name, Context) {}
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+ std::optional<TraversalKind> getCheckTraversalKind() const override {
+ return TK_IgnoreUnlessSpelledInSource;
+ }
};
} // namespace clang::tidy::bugprone
Index: clang-tools-extra/test/clang-tidy/checkers/bugprone/branch-clone.cpp
===================================================================
--- clang-tools-extra/test/clang-tidy/checkers/bugprone/branch-clone.cpp
+++ clang-tools-extra/test/clang-tidy/checkers/bugprone/branch-clone.cpp
@@ -1024,3 +1024,37 @@
SEMICOLON_CASE_COLON(3);
}
}
+
+namespace PR62693 {
+ class Object {
+ public:
+ template <typename T>
+ bool ConvertableTo() const;
+
+ template <typename T>
+ void Handle();
+ };
+
+ template <typename T>
+ void update(Object &a) {
+ if (a.ConvertableTo<char *>()) {
+ a.Handle<char *>();
+ } else {
+ a.Handle<T>();
+ }
+ }
+
+ template <typename T>
+ void update2(Object &a) {
+ if (a.ConvertableTo<char *>()) {
+ a.Handle<char *>();
+ } else {
+ a.Handle<T>();
+ }
+ }
+
+ void foo(Object &a) {
+ update<int>(a);
+ update2<char *>(a);
+ }
+}
Index: clang-tools-extra/docs/ReleaseNotes.rst
===================================================================
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -201,6 +201,11 @@
Changes in existing checks
^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+- Fixed false-positive in :doc:`bugprone-branch-clone
+ <clang-tidy/checks/bugprone/branch-clone>` check by ignoring auto-generated
+ code, template instances, and implicit code patterns.
+
- Improved :doc:`readability-redundant-string-cstr
<clang-tidy/checks/readability/redundant-string-cstr>` check to recognise
unnecessary ``std::string::c_str()`` and ``std::string::data()`` calls in
Index: clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.h
===================================================================
--- clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.h
+++ clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.h
@@ -27,6 +27,9 @@
: ClangTidyCheck(Name, Context) {}
void registerMatchers(ast_matchers::MatchFinder *Finder) override;
void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+ std::optional<TraversalKind> getCheckTraversalKind() const override {
+ return TK_IgnoreUnlessSpelledInSource;
+ }
};
} // namespace clang::tidy::bugprone
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits