1 // RUN: %clang_cc1 -ffreestanding -Eonly -verify %s
3 // Try different path permutations of __has_include with existing file.
4 #if __has_include("stdint.h")
6 #error "__has_include failed (1)."
9 #if __has_include(<stdint.h>)
11 #error "__has_include failed (2)."
14 // Try unary expression.
15 #if !__has_include("stdint.h")
16 #error "__has_include failed (5)."
19 // Try binary expression.
20 #if __has_include("stdint.h") && __has_include("stddef.h")
22 #error "__has_include failed (6)."
25 // Try non-existing file.
26 #if __has_include("blahblah.h")
27 #error "__has_include failed (7)."
31 #if !defined(__has_include)
32 #error "defined(__has_include) failed (8)."
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}}
38 #error "__has_include failed (1)."
41 #if __has_include_next(<stddef.h>) // expected-warning {{#include_next in primary source file}}
43 #error "__has_include failed (2)."
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)."
51 // Try binary expression.
52 #if __has_include_next("stdint.h") && __has_include("stddef.h") // expected-warning {{#include_next in primary source file}}
54 #error "__has_include_next failed (6)."
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)."
63 #if !defined(__has_include_next)
64 #error "defined(__has_include_next) failed (8)."
68 #define MACRO1 __has_include(<stdint.h>)
69 #define MACRO2 ("stdint.h")
70 #define MACRO3 ("blahblah.h")
71 #define MACRO4 blahblah.h>)
72 #define MACRO5 <stdint.h>
75 #error "__has_include with macro failed (1)."
78 #if !__has_include MACRO2
79 #error "__has_include with macro failed (2)."
82 #if __has_include MACRO3
83 #error "__has_include with macro failed (3)."
86 #if __has_include(<MACRO4
87 #error "__has_include with macro failed (4)."
90 #if !__has_include(MACRO5)
91 #error "__has_include with macro failed (2)."
94 // Try as non-preprocessor directives
96 __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}}
97 __has_include("stdint.h") // expected-error {{'__has_include' must be used within a preprocessing directive}}
100 MACRO1
// expected-error {{'__has_include' must be used within a preprocessing directive}}
103 MACRO1
// expected-error {{'__has_include' must be used within a preprocessing directive}}
108 MACRO1
// expected-error {{'__has_include' must be used within a preprocessing directive}}
112 MACRO1
// This should be fine because it is never actually reached
116 // Try badly formed expressions.
117 // FIXME: We can recover better in almost all of these cases. (PR13335)
119 // expected-error@+1 {{missing '(' after '__has_include'}}
120 #if __has_include "stdint.h")
123 // expected-error@+1 {{expected "FILENAME" or <FILENAME>}} expected-error@+1 {{token is not a valid binary operator in a preprocessor subexpression}}
124 #if __has_include(stdint.h)
127 // expected-error@+1 {{expected "FILENAME" or <FILENAME>}}
131 // expected-error@+1 {{missing '(' after '__has_include'}}
135 // expected-error@+1 {{missing '(' after '__has_include'}}
136 #if __has_include<stdint.h>)
139 // expected-error@+1 {{expected "FILENAME" or <FILENAME>}} expected-warning@+1 {{missing terminating '"' character}} expected-error@+1 {{invalid token at start of a preprocessor expression}}
140 #if __has_include("stdint.h)
143 // 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}}
144 #if __has_include(stdint.h")
147 // expected-error@+1 {{expected "FILENAME" or <FILENAME>}} expected-error@+1 {{token is not a valid binary operator in a preprocessor subexpression}}
148 #if __has_include(stdint.h>)
151 // expected-error@+1 {{'__has_include' must be used within a preprocessing directive}}
154 // expected-error@+1 {{missing ')' after '__has_include'}} // expected-error@+1 {{expected value in expression}} // expected-note@+1 {{to match this '('}}
155 #if __has_include("stdint.h"
158 // expected-error@+1 {{expected "FILENAME" or <FILENAME>}} // expected-error@+1 {{expected value in expression}}
162 // expected-error@+1 {{missing '(' after '__has_include'}} // expected-error@+1 {{expected value in expression}}
166 // expected-error@+1 {{missing '(' after '__has_include'}}
170 // expected-error@+1 {{expected "FILENAME" or <FILENAME>}}
171 #if __has_include('x'
174 // expected-error@+1 {{expected "FILENAME" or <FILENAME}} expected-error@+1 {{expected end of line in preprocessor expression}}
175 #if __has_include('x')
178 // expected-error@+1 {{missing ')' after '__has_include'}} // expected-error@+1 {{expected value in expression}} // expected-note@+1 {{to match this '('}}
179 #if __has_include(<stdint.h>
182 // expected-error@+1 {{expected '>'}} expected-note@+1 {{to match this '<'}} // expected-error@+1 {{expected value in expression}}
183 #if __has_include(<stdint.h)
186 #define HAS_INCLUDE(header) __has_include(header)
187 #if HAS_INCLUDE(<stdint.h>)
189 #error "__has_include failed (9)."
193 #elif __has_include(<foo>)
198 #elif __has_include(<foo>)