[PATCH] D7375: [clang-tidy] Assert related checkers
Roman Lebedev via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Mar 24 12:59:46 PDT 2017
lebedev.ri added inline comments.
================
Comment at: test/clang-tidy/misc-assert-side-effect.cpp:67
+
+ assert(freeFunction());
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found assert() with side effect
----------------
Is it intentional that the check also warns on free functions even if they are marked as const, .e.g:
cat >test.cpp <<EOL
```
#include <cassert>
// only works for positive values and zero
template <typename T>
inline constexpr bool __attribute__((const))
isPowerOfTwo(T val) {
return (val & (~val+1)) == val;
}
int main()
{
assert(isPowerOfTwo(2 << 2));
}
```
EOL
Run:
```
$ clang-tidy -checks misc-assert-side-effect -config="{Checks: 'misc-assert-side-effect', CheckOptions: [{key: 'misc-assert-side-effect.CheckFunctionCalls', value: 1}]}" test.cpp -- -std=c++11
/tmp/test.cpp:14:3: warning: found assert() with side effect [misc-assert-side-effect]
assert(isPowerOfTwo(2 << 2));
^
/usr/include/assert.h:89:4: note: expanded from macro 'assert'
((expr) \
^
```
Am i missing something obvious?
https://reviews.llvm.org/D7375
More information about the cfe-commits
mailing list