Implicit code like, template instances, compiler generated
code are not excluded in this check by using
TK_IgnoreUnlessSpelledInSource.
Fixes #62693
Differential D151133
[clang-tidy] Ignore implicit code in bugprone-branch-clone PiotrZSL on May 22 2023, 11:58 AM. Authored by
Details Implicit code like, template instances, compiler generated Fixes #62693
Diff Detail
Event TimelineComment Actions For me it's an unfortunate surprise that Clang Tidy is only seeing the result of the template instantiation process where the type variables are substituted (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're in templates.) Comment Actions If this freshly added testcase passes, then there is no reason to delay merging this commit. Thanks for the contribution :) ! |