[PATCH] Fix for Bug 22880
Szabolcs Sipos
szabolcs.sipos at ericsson.com
Fri Mar 13 13:02:54 PDT 2015
Hi alexfh,
The misc-static-assert check will not warn on assert(false), assert(False), assert(FALSE); where false / False / FALSE are macros expanding to the false or 0 literals.
Also added corresponding test cases.
[[ https://llvm.org/bugs/show_bug.cgi?id=22880 | Bug 22880 ]]
http://reviews.llvm.org/D8328
Files:
clang-tidy/misc/StaticAssertCheck.cpp
test/clang-tidy/misc-static-assert.cpp
Index: clang-tidy/misc/StaticAssertCheck.cpp
===================================================================
--- clang-tidy/misc/StaticAssertCheck.cpp
+++ clang-tidy/misc/StaticAssertCheck.cpp
@@ -75,9 +75,18 @@
return;
// False literal is not the result of macro expansion.
- if (IsAlwaysFalse &&
- !SM.getImmediateSpellingLoc(IsAlwaysFalse->getExprLoc()).isMacroID())
- return;
+ if (IsAlwaysFalse) {
+ SourceLocation FalseLiteralLoc =
+ SM.getImmediateSpellingLoc(IsAlwaysFalse->getExprLoc());
+ if (!FalseLiteralLoc.isMacroID())
+ return;
+
+ StringRef FalseMacroName =
+ Lexer::getImmediateMacroName(FalseLiteralLoc, SM, Opts);
+ if (FalseMacroName == "false" || FalseMacroName == "False" ||
+ FalseMacroName == "FALSE")
+ return;
+ }
SourceLocation AssertLoc = SM.getImmediateMacroCallerLoc(AssertExpansionLoc);
Index: test/clang-tidy/misc-static-assert.cpp
===================================================================
--- test/clang-tidy/misc-static-assert.cpp
+++ test/clang-tidy/misc-static-assert.cpp
@@ -12,6 +12,9 @@
#define ZERO_MACRO 0
+#define False false
+#define FALSE false
+
#define my_macro() assert(0 == 1)
// CHECK-FIXES: #define my_macro() assert(0 == 1)
@@ -60,6 +63,11 @@
assert(false);
// CHECK-FIXES: {{^ }}assert(false);
+ assert(False);
+ // CHECK-FIXES: {{^ }}assert(False);
+ assert(FALSE);
+ // CHECK-FIXES: {{^ }}assert(FALSE);
+
assert(ZERO_MACRO);
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found assert() that could be
// CHECK-FIXES: {{^ }}static_assert(ZERO_MACRO, "");
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D8328.21948.patch
Type: text/x-patch
Size: 1625 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150313/14131513/attachment.bin>
More information about the cfe-commits
mailing list