[clang-tidy] Fix for llvm.org/PR23572

misc-static-assert won't report asserts whose conditions contain calls to non constexpr functions.

llvm-svn: 238098
This commit is contained in:
Szabolcs Sipos 2015-05-23 14:21:01 +00:00
parent 5f2a1379ef
commit 0acf19ed53
2 changed files with 9 additions and 1 deletions

View File

@ -39,11 +39,13 @@ void StaticAssertCheck::registerMatchers(MatchFinder *Finder) {
anyOf(binaryOperator(hasEitherOperand(IsAlwaysFalseWithCast)),
anything())).bind("assertExprRoot"),
IsAlwaysFalse);
auto NonConstexprFunctionCall =
callExpr(hasDeclaration(functionDecl(unless(isConstexpr()))));
auto Condition = expr(anyOf(
expr(ignoringParenCasts(anyOf(
AssertExprRoot,
unaryOperator(hasUnaryOperand(ignoringParenCasts(AssertExprRoot)))))),
anything()));
anything()), unless(findAll(NonConstexprFunctionCall)));
Finder->addMatcher(
stmt(anyOf(conditionalOperator(hasCondition(Condition.bind("condition"))),

View File

@ -20,6 +20,9 @@ void abort() {}
constexpr bool myfunc(int a, int b) { return a * b == 0; }
typedef __SIZE_TYPE__ size_t;
extern "C" size_t strlen(const char *s);
class A {
public:
bool method() { return true; }
@ -120,5 +123,8 @@ int main() {
// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found assert() that could be
// CHECK-FIXES: {{^ }}static_assert(10==5 , "Report me!");
assert(strlen("12345") == 5);
// CHECK-FIXES: {{^ }}assert(strlen("12345") == 5);
return 0;
}