diff options
author | Aaron Ballman <aaron@aaronballman.com> | 2015-08-28 19:27:19 +0000 |
---|---|---|
committer | Aaron Ballman <aaron@aaronballman.com> | 2015-08-28 19:27:19 +0000 |
commit | 327e97bb37ec535f134b0b3e7ecbb9c181ad4f4c (patch) | |
tree | 787f0b09c43bf1d18e7b891e8f6d33cd4bbc5956 /clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp | |
parent | ff7da34bc36d2859076876637ad2b04796cbb81c (diff) | |
download | llvm-327e97bb37ec535f134b0b3e7ecbb9c181ad4f4c.zip llvm-327e97bb37ec535f134b0b3e7ecbb9c181ad4f4c.tar.gz llvm-327e97bb37ec535f134b0b3e7ecbb9c181ad4f4c.tar.bz2 |
Disable clang-tidy misc checkers when not compiling in C++ mode. Many of the checkers do not require additional testing as the tests will not compile for other languages or modes, or the checkers would never match a valid construct.
llvm-svn: 246318
Diffstat (limited to 'clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp')
-rw-r--r-- | clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp | 72 |
1 files changed, 42 insertions, 30 deletions
diff --git a/clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp b/clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp index 1b6b897..e5aa86e 100644 --- a/clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp +++ b/clang-tools-extra/clang-tidy/misc/StaticAssertCheck.cpp @@ -27,34 +27,47 @@ StaticAssertCheck::StaticAssertCheck(StringRef Name, ClangTidyContext *Context) : ClangTidyCheck(Name, Context) {} void StaticAssertCheck::registerMatchers(MatchFinder *Finder) { - auto IsAlwaysFalse = expr(ignoringParenImpCasts( - expr(anyOf(boolLiteral(equals(false)), integerLiteral(equals(0)), - nullPtrLiteralExpr(), gnuNullExpr())).bind("isAlwaysFalse"))); - auto IsAlwaysFalseWithCast = ignoringParenImpCasts(anyOf(IsAlwaysFalse, - cStyleCastExpr(has(IsAlwaysFalse)).bind("castExpr"))); - auto AssertExprRoot = anyOf( - binaryOperator( - anyOf(hasOperatorName("&&"), hasOperatorName("==")), - hasEitherOperand(ignoringImpCasts(stringLiteral().bind("assertMSG"))), - anyOf(binaryOperator(hasEitherOperand(IsAlwaysFalseWithCast)), - anything())).bind("assertExprRoot"), - IsAlwaysFalse); - auto NonConstexprFunctionCall = - callExpr(hasDeclaration(functionDecl(unless(isConstexpr())))); - auto AssertCondition = expr(anyOf( - expr(ignoringParenCasts(anyOf( - AssertExprRoot, - unaryOperator(hasUnaryOperand(ignoringParenCasts(AssertExprRoot)))))), - anything()), unless(findAll(NonConstexprFunctionCall))).bind("condition"); - auto Condition = anyOf(ignoringParenImpCasts(callExpr( - hasDeclaration(functionDecl(hasName("__builtin_expect"))), - hasArgument(0, AssertCondition))), AssertCondition); - - Finder->addMatcher( - stmt(anyOf(conditionalOperator(hasCondition(Condition)), - ifStmt(hasCondition(Condition))), - unless(isInTemplateInstantiation())).bind("condStmt"), - this); + // FIXME: I don't see why this checker couldn't also be interesting for + // _Static_assert in C11, or static_assert if <assert.h> has been included, + // but it is currently only enabled for C++11. Investigate. + if (getLangOpts().CPlusPlus11) { + auto IsAlwaysFalse = expr(ignoringParenImpCasts( + expr(anyOf(boolLiteral(equals(false)), integerLiteral(equals(0)), + nullPtrLiteralExpr(), gnuNullExpr())) + .bind("isAlwaysFalse"))); + auto IsAlwaysFalseWithCast = ignoringParenImpCasts(anyOf( + IsAlwaysFalse, cStyleCastExpr(has(IsAlwaysFalse)).bind("castExpr"))); + auto AssertExprRoot = + anyOf(binaryOperator( + anyOf(hasOperatorName("&&"), hasOperatorName("==")), + hasEitherOperand( + ignoringImpCasts(stringLiteral().bind("assertMSG"))), + anyOf(binaryOperator(hasEitherOperand(IsAlwaysFalseWithCast)), + anything())) + .bind("assertExprRoot"), + IsAlwaysFalse); + auto NonConstexprFunctionCall = + callExpr(hasDeclaration(functionDecl(unless(isConstexpr())))); + auto AssertCondition = + expr(anyOf(expr(ignoringParenCasts( + anyOf(AssertExprRoot, + unaryOperator(hasUnaryOperand( + ignoringParenCasts(AssertExprRoot)))))), + anything()), + unless(findAll(NonConstexprFunctionCall))) + .bind("condition"); + auto Condition = + anyOf(ignoringParenImpCasts(callExpr( + hasDeclaration(functionDecl(hasName("__builtin_expect"))), + hasArgument(0, AssertCondition))), + AssertCondition); + + Finder->addMatcher(stmt(anyOf(conditionalOperator(hasCondition(Condition)), + ifStmt(hasCondition(Condition))), + unless(isInTemplateInstantiation())) + .bind("condStmt"), + this); + } } void StaticAssertCheck::check(const MatchFinder::MatchResult &Result) { @@ -70,8 +83,7 @@ void StaticAssertCheck::check(const MatchFinder::MatchResult &Result) { const auto *CastExpr = Result.Nodes.getNodeAs<CStyleCastExpr>("castExpr"); SourceLocation AssertExpansionLoc = CondStmt->getLocStart(); - if (!Opts.CPlusPlus11 || !AssertExpansionLoc.isValid() || - !AssertExpansionLoc.isMacroID()) + if (!AssertExpansionLoc.isValid() || !AssertExpansionLoc.isMacroID()) return; StringRef MacroName = |