[PATCH] D151133: [clang-tidy] Ignore implicit code in bugprone-branch-clone

DonĂ¡t Nagy via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue May 23 05:07:55 PDT 2023


donat.nagy added a comment.

For me it's an unfortunate surprise that Clang Tidy is traversing the concrete //template instantiation// (I would've guessed that it's working on the original template body), but if that's the observed behavior, then this commit is a clean and straightforward fix.

I'd suggest adding another testcase that looks like

  template <typename T>
  int branch_clone_in_template(T t) {
    if (t) {
      return 42;
    } else {
      return 42;
    }
  }
  int use_template(int x) {
    return branch_clone_in_template<int>(x);
  }

to clarify the behavior on cases where the checker encounters a "real" branch clone that happens to be in a template. I think we can/should merge your change even if it suppresses these true positives (as it's a self-contained change that replaces a serious issue with a minor limitation), but in that case we should mark this testcase with a FIXME comment to highlight this low-priority followup work. (Of course it's even better if you happen to have a quick idea which ensures that the checker can report "real" branch clones even if they happen to appear in templates.)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151133/new/

https://reviews.llvm.org/D151133



More information about the cfe-commits mailing list