diff options
author | Aaron Ballman <aaron@aaronballman.com> | 2015-08-31 21:54:42 +0000 |
---|---|---|
committer | Aaron Ballman <aaron@aaronballman.com> | 2015-08-31 21:54:42 +0000 |
commit | c0dc76c2519b5700f5f9c081ed5a094775dd8780 (patch) | |
tree | b688c54687b24808052036249231eb88077665e9 /clang-tools-extra/test/clang-tidy/misc-static-assert.c | |
parent | f444177d00080830fd2d89152724b385e31fcd39 (diff) | |
download | bcm5719-llvm-c0dc76c2519b5700f5f9c081ed5a094775dd8780.tar.gz bcm5719-llvm-c0dc76c2519b5700f5f9c081ed5a094775dd8780.zip |
Allow the static assert clang-tidy checker to run over C code.
llvm-svn: 246495
Diffstat (limited to 'clang-tools-extra/test/clang-tidy/misc-static-assert.c')
-rw-r--r-- | clang-tools-extra/test/clang-tidy/misc-static-assert.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/clang-tools-extra/test/clang-tidy/misc-static-assert.c b/clang-tools-extra/test/clang-tidy/misc-static-assert.c new file mode 100644 index 00000000000..aa0b7ee2b9f --- /dev/null +++ b/clang-tools-extra/test/clang-tidy/misc-static-assert.c @@ -0,0 +1,27 @@ +// RUN: %python %S/check_clang_tidy.py %s misc-static-assert %t -- -std=c11
+// RUN: clang-tidy %s -checks=-*,misc-static-assert -- -std=c99 | count 0
+
+void abort() {}
+#ifdef NDEBUG
+#define assert(x) 1
+#else
+#define assert(x) \
+ if (!(x)) \
+ abort()
+#endif
+
+void f(void) {
+ int x = 1;
+ assert(x == 0);
+ // CHECK-FIXES: {{^ }}assert(x == 0);
+
+ #define static_assert(x, msg) _Static_assert(x, msg)
+ assert(11 == 5 + 6);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found assert() that could be
+ // CHECK-FIXES: {{^ }}static_assert(11 == 5 + 6, "");
+ #undef static_assert
+
+ assert(10 == 5 + 5);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: found assert() that could be
+ // CHECK-FIXES: {{^ }}static_assert(10 == 5 + 5, "");
+}
|