diff options
author | Alexander Kornienko <alexfh@google.com> | 2015-03-15 02:19:37 +0000 |
---|---|---|
committer | Alexander Kornienko <alexfh@google.com> | 2015-03-15 02:19:37 +0000 |
commit | 1c4af5edf4e92f1436b6668ab665dea42d512834 (patch) | |
tree | e26920756f51b1d22b4698bd863d981bb60f6b6e /clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp | |
parent | b0464089fd7c36c8c1179dbdbd0ec000a0b3d6a8 (diff) | |
download | llvm-1c4af5edf4e92f1436b6668ab665dea42d512834.zip llvm-1c4af5edf4e92f1436b6668ab665dea42d512834.tar.gz llvm-1c4af5edf4e92f1436b6668ab665dea42d512834.tar.bz2 |
[clang-tidy] Fix false positives in the misc-static-assert check http://llvm.org/PR22880
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.
http://reviews.llvm.org/D8328
Patch by Szabolcs Sipos!
llvm-svn: 232306
Diffstat (limited to 'clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp')
-rw-r--r-- | clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp b/clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp index fd6c4ca..91451e6 100644 --- a/clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp +++ b/clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp @@ -75,9 +75,17 @@ void StaticAssertCheck::check(const MatchFinder::MatchResult &Result) { 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.compare_lower("false") == 0) + return; + } SourceLocation AssertLoc = SM.getImmediateMacroCallerLoc(AssertExpansionLoc); |