This revision was automatically updated to reflect the committed changes. Closed by commit rG42c83e32706e: [clang-tidy] Ignore implicit code in bugprone-branch-clone (authored by PiotrZSL).
Changed prior to commit: https://reviews.llvm.org/D151133?vs=524764&id=524845#toc Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D151133/new/ 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,48 @@ 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); + } + + template <typename T> + int branch_clone_in_template(T t) { + // CHECK-MESSAGES: :[[@LINE+2]]:5: warning: if with identical then and else branches [bugprone-branch-clone] + // CHECK-MESSAGES: :[[@LINE+3]]:7: note: else branch starts here + if (t) { + return 42; + } else { + return 42; + } + } +} Index: clang-tools-extra/docs/ReleaseNotes.rst =================================================================== --- clang-tools-extra/docs/ReleaseNotes.rst +++ clang-tools-extra/docs/ReleaseNotes.rst @@ -202,9 +202,10 @@ Changes in existing checks ^^^^^^^^^^^^^^^^^^^^^^^^^^ -- Fixed false-positive in :doc:`bugprone-branch-clone - <clang-tidy/checks/bugprone/branch-clone>` check by ignoring duplicated - switch cases marked with the ``[[fallthrough]]`` attribute. +- Fixed false-positives in :doc:`bugprone-branch-clone + <clang-tidy/checks/bugprone/branch-clone>` check by ignoring auto-generated + code, template instances, implicit code patterns and duplicated switch cases + marked with the ``[[fallthrough]]`` attribute. - Improved :doc:`readability-redundant-string-cstr <clang-tidy/checks/readability/redundant-string-cstr>` check to recognise 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,48 @@ 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); + } + + template <typename T> + int branch_clone_in_template(T t) { + // CHECK-MESSAGES: :[[@LINE+2]]:5: warning: if with identical then and else branches [bugprone-branch-clone] + // CHECK-MESSAGES: :[[@LINE+3]]:7: note: else branch starts here + if (t) { + return 42; + } else { + return 42; + } + } +} Index: clang-tools-extra/docs/ReleaseNotes.rst =================================================================== --- clang-tools-extra/docs/ReleaseNotes.rst +++ clang-tools-extra/docs/ReleaseNotes.rst @@ -202,9 +202,10 @@ Changes in existing checks ^^^^^^^^^^^^^^^^^^^^^^^^^^ -- Fixed false-positive in :doc:`bugprone-branch-clone - <clang-tidy/checks/bugprone/branch-clone>` check by ignoring duplicated - switch cases marked with the ``[[fallthrough]]`` attribute. +- Fixed false-positives in :doc:`bugprone-branch-clone + <clang-tidy/checks/bugprone/branch-clone>` check by ignoring auto-generated + code, template instances, implicit code patterns and duplicated switch cases + marked with the ``[[fallthrough]]`` attribute. - Improved :doc:`readability-redundant-string-cstr <clang-tidy/checks/readability/redundant-string-cstr>` check to recognise 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 cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits