1 // RUN: %clang_cc1 -ffreestanding -Eonly -verify %s
2 
3 // Try different path permutations of __has_include with existing file.
4 #if __has_include("stdint.h")
5 #else
6   #error "__has_include failed (1)."
7 #endif
8 
9 #if __has_include(<stdint.h>)
10 #else
11   #error "__has_include failed (2)."
12 #endif
13 
14 // Try unary expression.
15 #if !__has_include("stdint.h")
16   #error "__has_include failed (5)."
17 #endif
18 
19 // Try binary expression.
20 #if __has_include("stdint.h") && __has_include("stddef.h")
21 #else
22   #error "__has_include failed (6)."
23 #endif
24 
25 // Try non-existing file.
26 #if __has_include("blahblah.h")
27   #error "__has_include failed (7)."
28 #endif
29 
30 // Try defined.
31 #if !defined(__has_include)
32   #error "defined(__has_include) failed (8)."
33 #endif
34 
35 // Try different path permutations of __has_include_next with existing file.
36 #if __has_include_next("stddef.h") // expected-warning {{#include_next in primary source file}}
37 #else
38   #error "__has_include failed (1)."
39 #endif
40 
41 #if __has_include_next(<stddef.h>) // expected-warning {{#include_next in primary source file}}
42 #else
43   #error "__has_include failed (2)."
44 #endif
45 
46 // Try unary expression.
47 #if !__has_include_next("stdint.h") // expected-warning {{#include_next in primary source file}}
48   #error "__has_include_next failed (5)."
49 #endif
50 
51 // Try binary expression.
52 #if __has_include_next("stdint.h") && __has_include("stddef.h") // expected-warning {{#include_next in primary source file}}
53 #else
54   #error "__has_include_next failed (6)."
55 #endif
56 
57 // Try non-existing file.
58 #if __has_include_next("blahblah.h") // expected-warning {{#include_next in primary source file}}
59   #error "__has_include_next failed (7)."
60 #endif
61 
62 // Try defined.
63 #if !defined(__has_include_next)
64   #error "defined(__has_include_next) failed (8)."
65 #endif
66 
67 // Try badly formed expressions.
68 // FIXME: We can recover better in almost all of these cases. (PR13335)
69 
70 // expected-error@+1 {{missing '(' after '__has_include'}} expected-error@+1 {{expected end of line}}
71 #if __has_include "stdint.h")
72 #endif
73 
74 // expected-error@+1 {{expected "FILENAME" or <FILENAME>}} expected-error@+1 {{token is not a valid binary operator in a preprocessor subexpression}}
75 #if __has_include(stdint.h)
76 #endif
77 
78 // expected-error@+1 {{expected "FILENAME" or <FILENAME>}}
79 #if __has_include()
80 #endif
81 
82 // expected-error@+1 {{missing '(' after '__has_include'}}
83 #if __has_include)
84 #endif
85 
86 // expected-error@+1 {{missing '(' after '__has_include'}} expected-error@+1 {{token is not a valid binary operator in a preprocessor subexpression}}
87 #if __has_include<stdint.h>)
88 #endif
89 
90 // expected-error@+1 {{expected "FILENAME" or <FILENAME>}} expected-warning@+1 {{missing terminating '"' character}}
91 #if __has_include("stdint.h)
92 #endif
93 
94 // expected-error@+1 {{expected "FILENAME" or <FILENAME>}} expected-warning@+1 {{missing terminating '"' character}} expected-error@+1 {{token is not a valid binary operator in a preprocessor subexpression}}
95 #if __has_include(stdint.h")
96 #endif
97 
98 // expected-error@+1 {{expected "FILENAME" or <FILENAME>}} expected-error@+1 {{token is not a valid binary operator in a preprocessor subexpression}}
99 #if __has_include(stdint.h>)
100 #endif
101 
102 
103 // FIXME: These test cases cause the compiler to crash. (PR13334)
104 //#if __has_include("stdint.h"
105 //#if __has_include(
106 //#if __has_include
107 //#if __has_include(<stdint.h>
108 //#if __has_include(<stdint.h)
109 
110