Skip to content

Commit ec81289

Browse files
committed
[clang-tidy] bugprone-assert-side-effect: Improve warning message.
Drop redundant "found", specify what exactly is wrong with side effects in assert conditions. Differential Revision: https://reviews.llvm.org/D95515
1 parent 6cedffc commit ec81289

File tree

2 files changed

+13
-12
lines changed

2 files changed

+13
-12
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ void AssertSideEffectCheck::check(const MatchFinder::MatchResult &Result) {
117117
if (AssertMacroName.empty())
118118
return;
119119

120-
diag(Loc, "found %0() with side effect") << AssertMacroName;
120+
diag(Loc, "side effect in %0() condition discarded in release builds")
121+
<< AssertMacroName;
121122
}
122123

123124
} // namespace bugprone

clang-tools-extra/test/clang-tidy/checkers/bugprone-assert-side-effect.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,47 +68,47 @@ int main() {
6868
assert(X == 1);
6969

7070
assert(X = 1);
71-
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found assert() with side effect [bugprone-assert-side-effect]
71+
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: side effect in assert() condition discarded in release builds [bugprone-assert-side-effect]
7272
my_assert(X = 1);
73-
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found my_assert() with side effect
73+
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: side effect in my_assert() condition discarded in release builds
7474
convoluted_assert(X = 1);
75-
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found convoluted_assert() with side effect
75+
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: side effect in convoluted_assert() condition discarded in release builds
7676
not_my_assert(X = 1);
7777

7878
assert(++X);
79-
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found assert() with side effect
79+
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: side effect in assert() condition discarded in release builds
8080
assert(!B);
8181

8282
assert(B || true);
8383

8484
assert(freeFunction());
85-
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found assert() with side effect
85+
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: side effect in assert() condition discarded in release builds
8686

8787
MyClass mc;
8888
assert(mc.badFunc(0, 1));
89-
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found assert() with side effect
89+
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: side effect in assert() condition discarded in release builds
9090
assert(mc.goodFunc(0, 1));
9191

9292
MyClass mc2;
9393
assert(mc2 = mc);
94-
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found assert() with side effect
94+
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: side effect in assert() condition discarded in release builds
9595

9696
assert(-mc > 0);
9797

9898
MyClass *mcp;
9999
assert(mcp = new MyClass);
100-
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found assert() with side effect
100+
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: side effect in assert() condition discarded in release builds
101101

102102
assert((delete mcp, false));
103-
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found assert() with side effect
103+
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: side effect in assert() condition discarded in release builds
104104

105105
assert((throw 1, false));
106-
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found assert() with side effect
106+
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: side effect in assert() condition discarded in release builds
107107

108108
assert2(1 == 2 - 1);
109109

110110
msvc_assert(mc2 = mc);
111-
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found msvc_assert() with side effect
111+
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: side effect in msvc_assert() condition discarded in release builds
112112

113113
return 0;
114114
}

0 commit comments

Comments
 (0)