summaryrefslogtreecommitdiffstats
path: root/clang/test
diff options
context:
space:
mode:
authorRichard Trieu <rtrieu@google.com>2013-06-12 21:20:57 +0000
committerRichard Trieu <rtrieu@google.com>2013-06-12 21:20:57 +0000
commit33a4b3db0de5fbba06264a46f560220b5f8f11a8 (patch)
treebe7f0fa608cba875aadb51581141eb56cff06290 /clang/test
parent2bb2aa27bfe729aa6d60b17cfafeaa959c7ea050 (diff)
downloadbcm5719-llvm-33a4b3db0de5fbba06264a46f560220b5f8f11a8.tar.gz
bcm5719-llvm-33a4b3db0de5fbba06264a46f560220b5f8f11a8.zip
Introducing -Wheader-guard, a warning that checks header guards actually work
properly. This warning checks that the #ifndef and #define directives at the beginning of a header refer to the same macro name. Includes a fix-it hint to correct the header guard. llvm-svn: 183867
Diffstat (limited to 'clang/test')
-rw-r--r--clang/test/Lexer/Inputs/bad-header-guard.h4
-rw-r--r--clang/test/Lexer/Inputs/different-define.h4
-rw-r--r--clang/test/Lexer/Inputs/good-header-guard.h4
-rw-r--r--clang/test/Lexer/Inputs/multiple.h4
-rw-r--r--clang/test/Lexer/Inputs/no-define.h3
-rw-r--r--clang/test/Lexer/Inputs/out-of-order-define.h7
-rw-r--r--clang/test/Lexer/Inputs/tokens-between-ifndef-and-define.h7
-rw-r--r--clang/test/Lexer/header.cpp33
8 files changed, 66 insertions, 0 deletions
diff --git a/clang/test/Lexer/Inputs/bad-header-guard.h b/clang/test/Lexer/Inputs/bad-header-guard.h
new file mode 100644
index 00000000000..601da093272
--- /dev/null
+++ b/clang/test/Lexer/Inputs/bad-header-guard.h
@@ -0,0 +1,4 @@
+#ifndef bad_header_guard
+#define bad_guard
+
+#endif
diff --git a/clang/test/Lexer/Inputs/different-define.h b/clang/test/Lexer/Inputs/different-define.h
new file mode 100644
index 00000000000..f23454b7c8c
--- /dev/null
+++ b/clang/test/Lexer/Inputs/different-define.h
@@ -0,0 +1,4 @@
+#ifndef different_define
+#define FOO 5
+
+#endif
diff --git a/clang/test/Lexer/Inputs/good-header-guard.h b/clang/test/Lexer/Inputs/good-header-guard.h
new file mode 100644
index 00000000000..664a479d391
--- /dev/null
+++ b/clang/test/Lexer/Inputs/good-header-guard.h
@@ -0,0 +1,4 @@
+#ifndef good_header_guard
+#define good_header_guard
+
+#endif
diff --git a/clang/test/Lexer/Inputs/multiple.h b/clang/test/Lexer/Inputs/multiple.h
new file mode 100644
index 00000000000..5dfb327a0b2
--- /dev/null
+++ b/clang/test/Lexer/Inputs/multiple.h
@@ -0,0 +1,4 @@
+#ifndef multiple
+#define multi
+
+#endif
diff --git a/clang/test/Lexer/Inputs/no-define.h b/clang/test/Lexer/Inputs/no-define.h
new file mode 100644
index 00000000000..591a66b30c6
--- /dev/null
+++ b/clang/test/Lexer/Inputs/no-define.h
@@ -0,0 +1,3 @@
+#ifndef no_define
+
+#endif
diff --git a/clang/test/Lexer/Inputs/out-of-order-define.h b/clang/test/Lexer/Inputs/out-of-order-define.h
new file mode 100644
index 00000000000..d38e93f29bb
--- /dev/null
+++ b/clang/test/Lexer/Inputs/out-of-order-define.h
@@ -0,0 +1,7 @@
+#ifndef out_of_order
+
+#define something_else
+
+#define out_of_order
+
+#endif
diff --git a/clang/test/Lexer/Inputs/tokens-between-ifndef-and-define.h b/clang/test/Lexer/Inputs/tokens-between-ifndef-and-define.h
new file mode 100644
index 00000000000..ce8d7705063
--- /dev/null
+++ b/clang/test/Lexer/Inputs/tokens-between-ifndef-and-define.h
@@ -0,0 +1,7 @@
+#ifndef tokens_between
+
+const int pi = 3;
+
+#define pi_is_bad
+
+#endif
diff --git a/clang/test/Lexer/header.cpp b/clang/test/Lexer/header.cpp
new file mode 100644
index 00000000000..278ff2e4323
--- /dev/null
+++ b/clang/test/Lexer/header.cpp
@@ -0,0 +1,33 @@
+// RUN: %clang_cc1 -fsyntax-only -Wno-header-guard %s
+// RUN: %clang_cc1 -fsyntax-only -Wheader-guard %s 2>&1 | FileCheck %s
+
+#include "Inputs/good-header-guard.h"
+#include "Inputs/no-define.h"
+#include "Inputs/different-define.h"
+#include "Inputs/out-of-order-define.h"
+#include "Inputs/tokens-between-ifndef-and-define.h"
+
+#include "Inputs/bad-header-guard.h"
+// CHECK: In file included from {{.*}}header.cpp:{{[0-9]*}}:
+// CHECK: {{.*}}bad-header-guard.h:1:9: warning: 'bad_header_guard' is used as a header guard here, followed by #define of a different macro
+// CHECK: {{^}}#ifndef bad_header_guard
+// CHECK: {{^}} ^~~~~~~~~~~~~~~~
+// CHECK: {{.*}}bad-header-guard.h:2:9: note: 'bad_guard' is defined here; did you mean 'bad_header_guard'?
+// CHECK: {{^}}#define bad_guard
+// CHECK: {{^}} ^~~~~~~~~
+// CHECK: {{^}} bad_header_guard
+
+#include "Inputs/multiple.h"
+#include "Inputs/multiple.h"
+#include "Inputs/multiple.h"
+#include "Inputs/multiple.h"
+// CHECK: In file included from {{.*}}header.cpp:{{[0-9]*}}:
+// CHECK: {{.*}}multiple.h:1:9: warning: 'multiple' is used as a header guard here, followed by #define of a different macro
+// CHECK: {{^}}#ifndef multiple
+// CHECK: {{^}} ^~~~~~~~
+// CHECK: {{.*}}multiple.h:2:9: note: 'multi' is defined here; did you mean 'multiple'?
+// CHECK: {{^}}#define multi
+// CHECK: {{^}} ^~~~~
+// CHECK: {{^}} multiple
+
+// CHECK: 2 warnings generated.
OpenPOWER on IntegriCloud