blob: 985501a2151f1e97f3bce33f11ad32236ee594d2 [file] [log] [blame]
Chandler Carruthba772ba2010-11-16 10:26:08 +00001// RUN: %clang_cc1 -ffreestanding -Eonly -verify %s
John Thompson92bd8c72009-11-02 22:28:12 +00002
3// Try different path permutations of __has_include with existing file.
Chandler Carruthba772ba2010-11-16 10:26:08 +00004#if __has_include("stdint.h")
John Thompson92bd8c72009-11-02 22:28:12 +00005#else
6 #error "__has_include failed (1)."
7#endif
8
Chandler Carruthba772ba2010-11-16 10:26:08 +00009#if __has_include(<stdint.h>)
John Thompson92bd8c72009-11-02 22:28:12 +000010#else
11 #error "__has_include failed (2)."
12#endif
13
14// Try unary expression.
Chandler Carruthba772ba2010-11-16 10:26:08 +000015#if !__has_include("stdint.h")
John Thompson92bd8c72009-11-02 22:28:12 +000016 #error "__has_include failed (5)."
17#endif
18
19// Try binary expression.
Chandler Carruthba772ba2010-11-16 10:26:08 +000020#if __has_include("stdint.h") && __has_include("stddef.h")
John Thompson92bd8c72009-11-02 22:28:12 +000021#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.
Chandler Carruthba772ba2010-11-16 10:26:08 +000047#if !__has_include_next("stdint.h") // expected-warning {{#include_next in primary source file}}
John Thompson92bd8c72009-11-02 22:28:12 +000048 #error "__has_include_next failed (5)."
49#endif
50
51// Try binary expression.
Chandler Carruthba772ba2010-11-16 10:26:08 +000052#if __has_include_next("stdint.h") && __has_include("stddef.h") // expected-warning {{#include_next in primary source file}}
John Thompson92bd8c72009-11-02 22:28:12 +000053#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
Eli Friedmana0f2d022013-01-09 02:20:00 +000067// Fun with macros
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>
73
74#if !MACRO1
75 #error "__has_include with macro failed (1)."
76#endif
77
78#if !__has_include MACRO2
79 #error "__has_include with macro failed (2)."
80#endif
81
82#if __has_include MACRO3
83 #error "__has_include with macro failed (3)."
84#endif
85
86#if __has_include(<MACRO4
87 #error "__has_include with macro failed (4)."
88#endif
89
90#if !__has_include(MACRO5)
91 #error "__has_include with macro failed (2)."
92#endif
93
John Thompson92bd8c72009-11-02 22:28:12 +000094// Try badly formed expressions.
Jordan Rose4b497562012-07-11 20:12:19 +000095// FIXME: We can recover better in almost all of these cases. (PR13335)
96
Richard Trieu97bc3d52012-10-22 20:28:48 +000097// expected-error@+1 {{missing '(' after '__has_include'}}
Jordan Rose4b497562012-07-11 20:12:19 +000098#if __has_include "stdint.h")
99#endif
100
101// expected-error@+1 {{expected "FILENAME" or <FILENAME>}} expected-error@+1 {{token is not a valid binary operator in a preprocessor subexpression}}
102#if __has_include(stdint.h)
103#endif
104
105// expected-error@+1 {{expected "FILENAME" or <FILENAME>}}
106#if __has_include()
107#endif
108
109// expected-error@+1 {{missing '(' after '__has_include'}}
110#if __has_include)
111#endif
112
Richard Trieu97bc3d52012-10-22 20:28:48 +0000113// expected-error@+1 {{missing '(' after '__has_include'}}
Jordan Rose4b497562012-07-11 20:12:19 +0000114#if __has_include<stdint.h>)
115#endif
116
Richard Trieu97bc3d52012-10-22 20:28:48 +0000117// expected-error@+1 {{expected "FILENAME" or <FILENAME>}} expected-warning@+1 {{missing terminating '"' character}} expected-error@+1 {{invalid token at start of a preprocessor expression}}
Jordan Rose4b497562012-07-11 20:12:19 +0000118#if __has_include("stdint.h)
119#endif
120
121// 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}}
122#if __has_include(stdint.h")
123#endif
124
125// expected-error@+1 {{expected "FILENAME" or <FILENAME>}} expected-error@+1 {{token is not a valid binary operator in a preprocessor subexpression}}
126#if __has_include(stdint.h>)
127#endif
128
Richard Trieu97bc3d52012-10-22 20:28:48 +0000129// expected-error@+1 {{missing '(' after '__has_include'}}
130__has_include
Jordan Rose4b497562012-07-11 20:12:19 +0000131
Richard Trieu97bc3d52012-10-22 20:28:48 +0000132// expected-error@+1 {{missing ')' after '__has_include'}} // expected-error@+1 {{expected value in expression}} // expected-note@+1 {{to match this '('}}
133#if __has_include("stdint.h"
134#endif
Jordan Rose4b497562012-07-11 20:12:19 +0000135
Richard Trieu97bc3d52012-10-22 20:28:48 +0000136// expected-error@+1 {{expected "FILENAME" or <FILENAME>}} // expected-error@+1 {{expected value in expression}}
137#if __has_include(
138#endif
139
140// expected-error@+1 {{missing '(' after '__has_include'}} // expected-error@+1 {{expected value in expression}}
141#if __has_include
142#endif
143
144// expected-error@+1 {{missing ')' after '__has_include'}} // expected-error@+1 {{expected value in expression}} // expected-note@+1 {{to match this '('}}
145#if __has_include(<stdint.h>
146#endif
147
148// expected-error@+1 {{expected "FILENAME" or <FILENAME>}} // expected-error@+1 {{expected value in expression}}
149#if __has_include(<stdint.h)
150#endif