summaryrefslogtreecommitdiffstats
path: root/test/Preprocessor/has_include.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/Preprocessor/has_include.c')
-rw-r--r--test/Preprocessor/has_include.c66
1 files changed, 65 insertions, 1 deletions
diff --git a/test/Preprocessor/has_include.c b/test/Preprocessor/has_include.c
index 10f7795..131e519 100644
--- a/test/Preprocessor/has_include.c
+++ b/test/Preprocessor/has_include.c
@@ -64,6 +64,55 @@
#error "defined(__has_include_next) failed (8)."
#endif
+// Fun with macros
+#define MACRO1 __has_include(<stdint.h>)
+#define MACRO2 ("stdint.h")
+#define MACRO3 ("blahblah.h")
+#define MACRO4 blahblah.h>)
+#define MACRO5 <stdint.h>
+
+#if !MACRO1
+ #error "__has_include with macro failed (1)."
+#endif
+
+#if !__has_include MACRO2
+ #error "__has_include with macro failed (2)."
+#endif
+
+#if __has_include MACRO3
+ #error "__has_include with macro failed (3)."
+#endif
+
+#if __has_include(<MACRO4
+ #error "__has_include with macro failed (4)."
+#endif
+
+#if !__has_include(MACRO5)
+ #error "__has_include with macro failed (2)."
+#endif
+
+// Try as non-preprocessor directives
+void foo( void ) {
+ __has_include_next("stdint.h") // expected-warning {{#include_next in primary source file}} expected-error {{__has_include_next must be used within a preprocessing directive}}
+ __has_include("stdint.h") // expected-error {{__has_include must be used within a preprocessing directive}}
+}
+
+MACRO1 // expected-error {{__has_include must be used within a preprocessing directive}}
+
+#if 1
+MACRO1 // expected-error {{__has_include must be used within a preprocessing directive}}
+#endif
+
+#if 0
+#elif 1
+MACRO1 // expected-error {{__has_include must be used within a preprocessing directive}}
+#endif
+
+#if 0
+MACRO1 // This should be fine because it is never actually reached
+#endif
+
+
// Try badly formed expressions.
// FIXME: We can recover better in almost all of these cases. (PR13335)
@@ -99,7 +148,7 @@
#if __has_include(stdint.h>)
#endif
-// expected-error@+1 {{missing '(' after '__has_include'}}
+// expected-error@+1 {{__has_include must be used within a preprocessing directive}}
__has_include
// expected-error@+1 {{missing ')' after '__has_include'}} // expected-error@+1 {{expected value in expression}} // expected-note@+1 {{to match this '('}}
@@ -121,3 +170,18 @@ __has_include
// expected-error@+1 {{expected "FILENAME" or <FILENAME>}} // expected-error@+1 {{expected value in expression}}
#if __has_include(<stdint.h)
#endif
+
+#define HAS_INCLUDE(header) __has_include(header)
+#if HAS_INCLUDE(<stdint.h>)
+#else
+ #error "__has_include failed (9)."
+#endif
+
+#if FOO
+#elif __has_include(<foo>)
+#endif
+
+// PR15539
+#ifdef FOO
+#elif __has_include(<foo>)
+#endif
OpenPOWER on IntegriCloud