Skip to content

Commit 2b51c8c

Browse files
committed
[clang-tidy] Clarify bugprone-branch-clone diagnostic message
This simple commit inserts "body" into the message "repeated branch _body_ in conditional chain". This is motivated by feedback from a user who (at first glance) thought that clang-tidy complained about a repeated branch _condition_. Differential Revision: https://reviews.llvm.org/D143917
1 parent df82394 commit 2b51c8c

File tree

4 files changed

+14
-14
lines changed

4 files changed

+14
-14
lines changed

clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ void BranchCloneCheck::check(const MatchFinder::MatchResult &Result) {
141141
if (NumCopies == 2) {
142142
// We report the first occurrence only when we find the second one.
143143
diag(Branches[I]->getBeginLoc(),
144-
"repeated branch in conditional chain");
144+
"repeated branch body in conditional chain");
145145
SourceLocation End =
146146
Lexer::getLocForEndOfToken(Branches[I]->getEndLoc(), 0,
147147
*Result.SourceManager, getLangOpts());

clang-tools-extra/test/clang-tidy/checkers/bugprone/branch-clone-if-constexpr-template.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ void handle(int);
55
template <unsigned Index>
66
void shouldFail() {
77
if constexpr (Index == 0) {
8-
// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: repeated branch in conditional chain [bugprone-branch-clone]
8+
// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: repeated branch body in conditional chain [bugprone-branch-clone]
99
handle(0);
1010
} else if constexpr (Index == 1) {
1111
handle(1);
@@ -28,7 +28,7 @@ void shouldPass() {
2828
void shouldFailNonTemplate() {
2929
constexpr unsigned Index = 1;
3030
if constexpr (Index == 0) {
31-
// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: repeated branch in conditional chain [bugprone-branch-clone]
31+
// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: repeated branch body in conditional chain [bugprone-branch-clone]
3232
handle(0);
3333
} else if constexpr (Index == 1) {
3434
handle(1);

clang-tools-extra/test/clang-tidy/checkers/bugprone/branch-clone-macro-crash.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ int y = 1;
99
d = b;
1010

1111
void f(void) {
12-
// CHECK-MESSAGES: warning: repeated branch in conditional chain [bugprone-branch-clone]
12+
// CHECK-MESSAGES: warning: repeated branch body in conditional chain [bugprone-branch-clone]
1313
a(x, y)
1414
}

clang-tools-extra/test/clang-tidy/checkers/bugprone/branch-clone.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ void test_macro13(int in, int &out) {
388388

389389
void test_chain1(int in, int &out) {
390390
if (in > 77)
391-
// CHECK-MESSAGES: :[[@LINE+1]]:5: warning: repeated branch in conditional chain [bugprone-branch-clone]
391+
// CHECK-MESSAGES: :[[@LINE+1]]:5: warning: repeated branch body in conditional chain [bugprone-branch-clone]
392392
out++;
393393
// CHECK-MESSAGES: :[[@LINE-1]]:10: note: end of the original
394394
else if (in > 55)
@@ -400,7 +400,7 @@ void test_chain1(int in, int &out) {
400400

401401
void test_chain2(int in, int &out) {
402402
if (in > 77)
403-
// CHECK-MESSAGES: :[[@LINE+1]]:5: warning: repeated branch in conditional chain [bugprone-branch-clone]
403+
// CHECK-MESSAGES: :[[@LINE+1]]:5: warning: repeated branch body in conditional chain [bugprone-branch-clone]
404404
out++;
405405
// CHECK-MESSAGES: :[[@LINE-1]]:10: note: end of the original
406406
else if (in > 55)
@@ -422,7 +422,7 @@ void test_chain2(int in, int &out) {
422422

423423
void test_chain3(int in, int &out) {
424424
if (in > 77) {
425-
// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: repeated branch in conditional chain [bugprone-branch-clone]
425+
// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: repeated branch body in conditional chain [bugprone-branch-clone]
426426
out++;
427427
out++;
428428
// CHECK-MESSAGES: :[[@LINE+1]]:4: note: end of the original
@@ -452,7 +452,7 @@ void test_chain3(int in, int &out) {
452452
// describes all branches of the first one before mentioning the second one.
453453
void test_chain4(int in, int &out) {
454454
if (in > 77) {
455-
// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: repeated branch in conditional chain [bugprone-branch-clone]
455+
// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: repeated branch body in conditional chain [bugprone-branch-clone]
456456
out++;
457457
out++;
458458
// CHECK-MESSAGES: :[[@LINE+1]]:4: note: end of the original
@@ -463,7 +463,7 @@ void test_chain4(int in, int &out) {
463463
out++;
464464
out++;
465465
} else if (in > 42)
466-
// CHECK-MESSAGES: :[[@LINE+1]]:5: warning: repeated branch in conditional chain [bugprone-branch-clone]
466+
// CHECK-MESSAGES: :[[@LINE+1]]:5: warning: repeated branch body in conditional chain [bugprone-branch-clone]
467467
out--;
468468
// CHECK-MESSAGES: :[[@LINE-1]]:10: note: end of the original
469469
else if (in > 28) {
@@ -485,7 +485,7 @@ void test_chain4(int in, int &out) {
485485

486486
void test_chain5(int in, int &out) {
487487
if (in > 77)
488-
// CHECK-MESSAGES: :[[@LINE+1]]:5: warning: repeated branch in conditional chain [bugprone-branch-clone]
488+
// CHECK-MESSAGES: :[[@LINE+1]]:5: warning: repeated branch body in conditional chain [bugprone-branch-clone]
489489
out++;
490490
// CHECK-MESSAGES: :[[@LINE-1]]:10: note: end of the original
491491
else if (in > 55)
@@ -507,7 +507,7 @@ void test_chain5(int in, int &out) {
507507

508508
void test_chain6(int in, int &out) {
509509
if (in > 77) {
510-
// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: repeated branch in conditional chain [bugprone-branch-clone]
510+
// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: repeated branch body in conditional chain [bugprone-branch-clone]
511511
out++;
512512
out++;
513513
// CHECK-MESSAGES: :[[@LINE+1]]:4: note: end of the original
@@ -538,7 +538,7 @@ void test_nested(int a, int b, int c, int &out) {
538538
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: if with identical then and else branches [bugprone-branch-clone]
539539
// CHECK-MESSAGES: :[[@LINE+27]]:5: note: else branch starts here
540540
if (b > 5) {
541-
// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: repeated branch in conditional chain [bugprone-branch-clone]
541+
// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: repeated branch body in conditional chain [bugprone-branch-clone]
542542
// CHECK-MESSAGES: :[[@LINE+9]]:6: note: end of the original
543543
// CHECK-MESSAGES: :[[@LINE+8]]:24: note: clone 1 starts here
544544
// CHECK-MESSAGES: :[[@LINE+14]]:12: note: clone 2 starts here
@@ -565,7 +565,7 @@ void test_nested(int a, int b, int c, int &out) {
565565
}
566566
} else {
567567
if (b > 5) {
568-
// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: repeated branch in conditional chain [bugprone-branch-clone]
568+
// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: repeated branch body in conditional chain [bugprone-branch-clone]
569569
// CHECK-MESSAGES: :[[@LINE+9]]:6: note: end of the original
570570
// CHECK-MESSAGES: :[[@LINE+8]]:24: note: clone 1 starts here
571571
// CHECK-MESSAGES: :[[@LINE+14]]:12: note: clone 2 starts here
@@ -948,7 +948,7 @@ char no_real_body(int in, int &out) {
948948
return 'A';
949949

950950
if (in > 77)
951-
// CHECK-MESSAGES: :[[@LINE+1]]:5: warning: repeated branch in conditional chain [bugprone-branch-clone]
951+
// CHECK-MESSAGES: :[[@LINE+1]]:5: warning: repeated branch body in conditional chain [bugprone-branch-clone]
952952
out++;
953953
// CHECK-MESSAGES: :[[@LINE-1]]:10: note: end of the original
954954
else if (in > 55)

0 commit comments

Comments
 (0)