summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/clang-tidy/modernize/UnaryStaticAssertCheck.cpp
diff options
context:
space:
mode:
authorGabor Horvath <xazax.hun@gmail.com>2017-07-12 13:43:35 +0000
committerGabor Horvath <xazax.hun@gmail.com>2017-07-12 13:43:35 +0000
commit53145213285e4322ec8cfbdd680840d89e230aa5 (patch)
tree515d3ac05cde8e6f35cd738c9d57a10bcdb65fe0 /clang-tools-extra/clang-tidy/modernize/UnaryStaticAssertCheck.cpp
parent8dfbc772d7639162f9ee2628de7eea94cd2b9b49 (diff)
downloadbcm5719-llvm-53145213285e4322ec8cfbdd680840d89e230aa5.tar.gz
bcm5719-llvm-53145213285e4322ec8cfbdd680840d89e230aa5.zip
[clang-tidy] Add new modernize use unary assert check
Patch by: Lilla Barancsuk Differential Revision: https://reviews.llvm.org/D35257 llvm-svn: 307791
Diffstat (limited to 'clang-tools-extra/clang-tidy/modernize/UnaryStaticAssertCheck.cpp')
-rw-r--r--clang-tools-extra/clang-tidy/modernize/UnaryStaticAssertCheck.cpp45
1 files changed, 45 insertions, 0 deletions
diff --git a/clang-tools-extra/clang-tidy/modernize/UnaryStaticAssertCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UnaryStaticAssertCheck.cpp
new file mode 100644
index 00000000000..c2129e315bf
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/modernize/UnaryStaticAssertCheck.cpp
@@ -0,0 +1,45 @@
+//===--- UnaryStaticAssertCheck.cpp - clang-tidy---------------------------===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+
+#include "UnaryStaticAssertCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace modernize {
+
+void UnaryStaticAssertCheck::registerMatchers(MatchFinder *Finder) {
+ if (!getLangOpts().CPlusPlus1z)
+ return;
+
+ Finder->addMatcher(staticAssertDecl().bind("static_assert"), this);
+}
+
+void UnaryStaticAssertCheck::check(const MatchFinder::MatchResult &Result) {
+ const auto *MatchedDecl =
+ Result.Nodes.getNodeAs<StaticAssertDecl>("static_assert");
+ const StringLiteral *AssertMessage = MatchedDecl->getMessage();
+
+ SourceLocation Loc = MatchedDecl->getLocation();
+
+ if (!AssertMessage || AssertMessage->getLength() ||
+ AssertMessage->getLocStart().isMacroID() || Loc.isMacroID())
+ return;
+
+ diag(Loc,
+ "use unary 'static_assert' when the string literal is an empty string")
+ << FixItHint::CreateRemoval(AssertMessage->getSourceRange());
+}
+
+} // namespace modernize
+} // namespace tidy
+} // namespace clang
OpenPOWER on IntegriCloud