summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/test/clang-tidy/readability-redundant-preprocessor-ifdef.cpp
diff options
context:
space:
mode:
authorMiklos Vajna <vmiklos@vmiklos.hu>2019-01-11 07:59:47 +0000
committerMiklos Vajna <vmiklos@vmiklos.hu>2019-01-11 07:59:47 +0000
commit98ef5337c9dfab72ad8f93a83b6429dfd0da168e (patch)
treeca8a7fb7c972c6b88dcf918f44ff6b2358864325 /clang-tools-extra/test/clang-tidy/readability-redundant-preprocessor-ifdef.cpp
parent114ad37c1dc805e1dfd694e076257f87f1b705d0 (diff)
downloadbcm5719-llvm-98ef5337c9dfab72ad8f93a83b6429dfd0da168e.tar.gz
bcm5719-llvm-98ef5337c9dfab72ad8f93a83b6429dfd0da168e.zip
[clang-tidy] new check 'readability-redundant-preprocessor'
Finds potentially redundant preprocessor directives. Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D54349 llvm-svn: 350922
Diffstat (limited to 'clang-tools-extra/test/clang-tidy/readability-redundant-preprocessor-ifdef.cpp')
-rw-r--r--clang-tools-extra/test/clang-tidy/readability-redundant-preprocessor-ifdef.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/clang-tools-extra/test/clang-tidy/readability-redundant-preprocessor-ifdef.cpp b/clang-tools-extra/test/clang-tidy/readability-redundant-preprocessor-ifdef.cpp
new file mode 100644
index 00000000000..72b608b1c2c
--- /dev/null
+++ b/clang-tools-extra/test/clang-tidy/readability-redundant-preprocessor-ifdef.cpp
@@ -0,0 +1,36 @@
+// RUN: %check_clang_tidy %s readability-redundant-preprocessor %t -- -- -DFOO
+
+// Positive testing.
+#ifdef FOO
+// CHECK-NOTES: [[@LINE+1]]:2: warning: nested redundant #ifdef; consider removing it [readability-redundant-preprocessor]
+#ifdef FOO
+// CHECK-NOTES: [[@LINE-3]]:2: note: previous #ifdef was here
+void f();
+#endif
+#endif
+
+// Positive testing of inverted condition.
+#ifdef FOO
+// CHECK-NOTES: [[@LINE+1]]:2: warning: nested redundant #ifndef; consider removing it [readability-redundant-preprocessor]
+#ifndef FOO
+// CHECK-NOTES: [[@LINE-3]]:2: note: previous #ifdef was here
+void f2();
+#endif
+#endif
+
+// Negative testing.
+#ifdef BAR
+void g();
+#endif
+
+#ifdef FOO
+#ifdef BAR
+void h();
+#endif
+#endif
+
+#ifdef FOO
+#ifndef BAR
+void i();
+#endif
+#endif
OpenPOWER on IntegriCloud