brintos

brintos / llvm-project-archived public Read only

0
0
Text · 6.7 KiB · ff199bf Raw
249 lines · c
1// RUN: %clang_cc1 -ffreestanding -Eonly -verify %s2 3// Try different path permutations of __has_include with existing file.4#if __has_include("stdint.h")5#else6  #error "__has_include failed (1)."7#endif8 9#if __has_include(<stdint.h>)10#else11  #error "__has_include failed (2)."12#endif13 14// Try unary expression.15#if !__has_include("stdint.h")16  #error "__has_include failed (5)."17#endif18 19// Try binary expression.20#if __has_include("stdint.h") && __has_include("stddef.h")21#else22  #error "__has_include failed (6)."23#endif24 25// Try non-existing file.26#if __has_include("blahblah.h")27  #error "__has_include failed (7)."28#endif29 30// Try defined.31#if !defined(__has_include)32  #error "defined(__has_include) failed (8)."33#endif34 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#else38  #error "__has_include failed (1)."39#endif40 41#if __has_include_next(<stddef.h>) // expected-warning {{#include_next in primary source file}}42#else43  #error "__has_include failed (2)."44#endif45 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#endif50 51// Try binary expression.52#if __has_include_next("stdint.h") && __has_include("stddef.h") // expected-warning {{#include_next in primary source file}}53#else54  #error "__has_include_next failed (6)."55#endif56 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#endif61 62// Try defined.63#if !defined(__has_include_next)64  #error "defined(__has_include_next) failed (8)."65#endif66 67// Fun with macros68#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 !MACRO175  #error "__has_include with macro failed (1)."76#endif77 78#if !__has_include MACRO279  #error "__has_include with macro failed (2)."80#endif81 82#if __has_include MACRO383  #error "__has_include with macro failed (3)."84#endif85 86#if __has_include(<MACRO487  #error "__has_include with macro failed (4)."88#endif89 90#if !__has_include(MACRO5)91  #error "__has_include with macro failed (2)."92#endif93 94// Try as non-preprocessor directives95void foo( void ) {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}}98}99 100MACRO1  // expected-error {{'__has_include' must be used within a preprocessing directive}}101 102#if 1103MACRO1  // expected-error {{'__has_include' must be used within a preprocessing directive}}104#endif105 106#if 0107#elif 1108MACRO1  // expected-error {{'__has_include' must be used within a preprocessing directive}}109#endif110 111#if 0112MACRO1  // This should be fine because it is never actually reached113#endif114 115 116// Try badly formed expressions.117// FIXME: We can recover better in almost all of these cases. (PR13335)118 119// expected-error@+1 {{missing '(' after '__has_include'}}120#if __has_include "stdint.h")121#endif122 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)125#endif126 127// expected-error@+1 {{expected "FILENAME" or <FILENAME>}}128#if __has_include()129#endif130 131// expected-error@+1 {{missing '(' after '__has_include'}}132#if __has_include)133#endif134 135// expected-error@+1 {{missing '(' after '__has_include'}}136#if __has_include<stdint.h>)137#endif138 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)141#endif142 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")145#endif146 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>)149#endif150 151// expected-error@+1 {{'__has_include' must be used within a preprocessing directive}}152__has_include153 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"156#endif157 158// expected-error@+1 {{expected "FILENAME" or <FILENAME>}} // expected-error@+1 {{expected value in expression}}159#if __has_include(160#endif161 162// expected-error@+1 {{missing '(' after '__has_include'}} // expected-error@+1 {{expected value in expression}}163#if __has_include164#endif165 166// expected-error@+1 {{missing '(' after '__has_include'}}167#if __has_include'x'168#endif169 170// expected-error@+1 {{expected "FILENAME" or <FILENAME>}}171#if __has_include('x'172#endif173 174// expected-error@+1 {{expected "FILENAME" or <FILENAME}} expected-error@+1 {{expected end of line in preprocessor expression}}175#if __has_include('x')176#endif177 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>180#endif181 182// expected-error@+1 {{expected '>'}} expected-note@+1 {{to match this '<'}} // expected-error@+1 {{expected value in expression}}183#if __has_include(<stdint.h)184#endif185 186#define HAS_INCLUDE(header) __has_include(header)187#if HAS_INCLUDE(<stdint.h>)188#else189  #error "__has_include failed (9)."190#endif191 192#if FOO193#elif __has_include(<foo>)194#endif195 196// PR15539197#ifdef FOO198#elif __has_include(<foo>)199#endif200 201#if __has_include(<stdint.h>\202)203#else204  #error "__has_include failed (10)."205#endif206 207#define MACRO6 <stdint.h>208#if __has_include(MACRO6\209)210#else211  #error "__has_include failed (11)."212#endif213 214#if __has_include_next(<stdint.h>/*expected-warning {{#include_next in primary source file}}*/\215)216#else217  #error "__has_include_next failed (9)."218#endif219 220#if __has_include_next(MACRO6/*expected-warning {{#include_next in primary source file}}*/\221) 222#else223  #error "__has_include_next failed (10)."224#endif225 226#define MACRO7 <std\227int.h>228#if __has_include(MACRO7)229#else230  #error "__has_include failed (12)."231#endif232 233#if __has_include(MACRO7\234)235#else236  #error "__has_include failed (13)."237#endif238 239#if __has_include_next(MACRO7) //expected-warning {{#include_next in primary source file}}240#else241  #error "__has_include_next failed (11)."242#endif243 244#if __has_include_next(MACRO7/*expected-warning {{#include_next in primary source file}}*/\245) 246#else247  #error "__has_include_next failed (12)."248#endif249