[clang-tools-extra] ec81289 - [clang-tidy] bugprone-assert-side-effect: Improve warning message.
Artem Dergachev via cfe-commits
cfe-commits at lists.llvm.org
Thu Jan 28 22:32:00 PST 2021
Author: Artem Dergachev
Date: 2021-01-28T22:31:49-08:00
New Revision: ec812898318036f6c33579b1d35c1a7f83cf112f
URL: https://github.com/llvm/llvm-project/commit/ec812898318036f6c33579b1d35c1a7f83cf112f
DIFF: https://github.com/llvm/llvm-project/commit/ec812898318036f6c33579b1d35c1a7f83cf112f.diff
LOG: [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
Added:
Modified:
clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.cpp
clang-tools-extra/test/clang-tidy/checkers/bugprone-assert-side-effect.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.cpp
index 8f7d1d1237e9..0d8834e4135f 100644
--- a/clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.cpp
@@ -117,7 +117,8 @@ void AssertSideEffectCheck::check(const MatchFinder::MatchResult &Result) {
if (AssertMacroName.empty())
return;
- diag(Loc, "found %0() with side effect") << AssertMacroName;
+ diag(Loc, "side effect in %0() condition discarded in release builds")
+ << AssertMacroName;
}
} // namespace bugprone
diff --git a/clang-tools-extra/test/clang-tidy/checkers/bugprone-assert-side-effect.cpp b/clang-tools-extra/test/clang-tidy/checkers/bugprone-assert-side-effect.cpp
index 0933402e90c4..bf368cda5e17 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/bugprone-assert-side-effect.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/bugprone-assert-side-effect.cpp
@@ -68,47 +68,47 @@ int main() {
assert(X == 1);
assert(X = 1);
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found assert() with side effect [bugprone-assert-side-effect]
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: side effect in assert() condition discarded in release builds [bugprone-assert-side-effect]
my_assert(X = 1);
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found my_assert() with side effect
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: side effect in my_assert() condition discarded in release builds
convoluted_assert(X = 1);
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found convoluted_assert() with side effect
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: side effect in convoluted_assert() condition discarded in release builds
not_my_assert(X = 1);
assert(++X);
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found assert() with side effect
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: side effect in assert() condition discarded in release builds
assert(!B);
assert(B || true);
assert(freeFunction());
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found assert() with side effect
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: side effect in assert() condition discarded in release builds
MyClass mc;
assert(mc.badFunc(0, 1));
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found assert() with side effect
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: side effect in assert() condition discarded in release builds
assert(mc.goodFunc(0, 1));
MyClass mc2;
assert(mc2 = mc);
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found assert() with side effect
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: side effect in assert() condition discarded in release builds
assert(-mc > 0);
MyClass *mcp;
assert(mcp = new MyClass);
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found assert() with side effect
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: side effect in assert() condition discarded in release builds
assert((delete mcp, false));
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found assert() with side effect
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: side effect in assert() condition discarded in release builds
assert((throw 1, false));
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found assert() with side effect
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: side effect in assert() condition discarded in release builds
assert2(1 == 2 - 1);
msvc_assert(mc2 = mc);
- // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found msvc_assert() with side effect
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: side effect in msvc_assert() condition discarded in release builds
return 0;
}
More information about the cfe-commits
mailing list