summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/test/clang-tidy/misc-multiple-statement-macro.cpp
diff options
context:
space:
mode:
authorSamuel Benzaquen <sbenza@google.com>2016-04-14 21:15:57 +0000
committerSamuel Benzaquen <sbenza@google.com>2016-04-14 21:15:57 +0000
commit4fa2d57c6db8c7c5e017761643606697c050787c (patch)
treeb5d64e06f0870cbd790306e8334bec61808321c8 /clang-tools-extra/test/clang-tidy/misc-multiple-statement-macro.cpp
parent1ca263c8903b765349d48490de1bfa7def0dc48d (diff)
downloadbcm5719-llvm-4fa2d57c6db8c7c5e017761643606697c050787c.tar.gz
bcm5719-llvm-4fa2d57c6db8c7c5e017761643606697c050787c.zip
[clang-tidy] Add check misc-multiple-statement-macro
Summary: The check detects multi-statement macros that are used in unbraced conditionals. Only the first statement will be part of the conditionals and the rest will fall outside of it and executed unconditionally. Reviewers: alexfh Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D18766 llvm-svn: 266369
Diffstat (limited to 'clang-tools-extra/test/clang-tidy/misc-multiple-statement-macro.cpp')
-rw-r--r--clang-tools-extra/test/clang-tidy/misc-multiple-statement-macro.cpp85
1 files changed, 85 insertions, 0 deletions
diff --git a/clang-tools-extra/test/clang-tidy/misc-multiple-statement-macro.cpp b/clang-tools-extra/test/clang-tidy/misc-multiple-statement-macro.cpp
new file mode 100644
index 00000000000..c943ee7c0f0
--- /dev/null
+++ b/clang-tools-extra/test/clang-tidy/misc-multiple-statement-macro.cpp
@@ -0,0 +1,85 @@
+// RUN: %check_clang_tidy %s misc-multiple-statement-macro %t
+
+void F();
+
+#define BAD_MACRO(x) \
+ F(); \
+ F()
+
+#define GOOD_MACRO(x) \
+ do { \
+ F(); \
+ F(); \
+ } while (0)
+
+#define GOOD_MACRO2(x) F()
+
+#define GOOD_MACRO3(x) F();
+
+#define MACRO_ARG_MACRO(X) \
+ if (54) \
+ X(2)
+
+#define ALL_IN_MACRO(X) \
+ if (43) \
+ F(); \
+ F()
+
+#define GOOD_NESTED(x) \
+ if (x) \
+ GOOD_MACRO3(x); \
+ F();
+
+#define IF(x) if(x)
+
+void positives() {
+ if (1)
+ BAD_MACRO(1);
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: multiple statement macro used without braces; some statements will be unconditionally executed [misc-multiple-statement-macro]
+ if (1) {
+ } else
+ BAD_MACRO(1);
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: multiple statement macro used
+ while (1)
+ BAD_MACRO(1);
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: multiple statement macro used
+ for (;;)
+ BAD_MACRO(1);
+ // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: multiple statement macro used
+
+ MACRO_ARG_MACRO(BAD_MACRO);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: multiple statement macro used
+ MACRO_ARG_MACRO(F(); int);
+ // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: multiple statement macro used
+ IF(1) BAD_MACRO(1);
+ // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: multiple statement macro used
+}
+
+void negatives() {
+ if (1) {
+ BAD_MACRO(1);
+ } else {
+ BAD_MACRO(1);
+ }
+ while (1) {
+ BAD_MACRO(1);
+ }
+ for (;;) {
+ BAD_MACRO(1);
+ }
+
+ if (1)
+ GOOD_MACRO(1);
+ if (1) {
+ GOOD_MACRO(1);
+ }
+ if (1)
+ GOOD_MACRO2(1);
+ if (1)
+ GOOD_MACRO3(1);
+
+ MACRO_ARG_MACRO(GOOD_MACRO);
+ ALL_IN_MACRO(1);
+
+ IF(1) GOOD_MACRO(1);
+}
OpenPOWER on IntegriCloud