[clang-tools-extra] r238098 - [clang-tidy] Fix for llvm.org/PR23572
Szabolcs Sipos
szabolcs.sipos at ericsson.com
Sat May 23 07:21:01 PDT 2015
Author: eszasip
Date: Sat May 23 09:21:01 2015
New Revision: 238098
URL: http://llvm.org/viewvc/llvm-project?rev=238098&view=rev
Log:
[clang-tidy] Fix for llvm.org/PR23572
misc-static-assert won't report asserts whose conditions contain calls to non constexpr functions.
Modified:
clang-tools-extra/trunk/clang-tidy/misc/StaticAssertCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/misc-static-assert.cpp
Modified: clang-tools-extra/trunk/clang-tidy/misc/StaticAssertCheck.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/StaticAssertCheck.cpp?rev=238098&r1=238097&r2=238098&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/misc/StaticAssertCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/StaticAssertCheck.cpp Sat May 23 09:21:01 2015
@@ -39,11 +39,13 @@ void StaticAssertCheck::registerMatchers
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"))),
Modified: clang-tools-extra/trunk/test/clang-tidy/misc-static-assert.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/misc-static-assert.cpp?rev=238098&r1=238097&r2=238098&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/misc-static-assert.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/misc-static-assert.cpp Sat May 23 09:21:01 2015
@@ -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;
}
More information about the cfe-commits
mailing list