1*67e74705SXin Li // RUN: %clang_cc1 %s -triple=i686-apple-darwin9 -verify -DVERIFY 2*67e74705SXin Li // RUN: %clang_cc1 %s -E -triple=i686-apple-darwin9 3*67e74705SXin Li #ifndef __has_feature 4*67e74705SXin Li #error Should have __has_feature 5*67e74705SXin Li #endif 6*67e74705SXin Li 7*67e74705SXin Li 8*67e74705SXin Li #if __has_feature(something_we_dont_have) 9*67e74705SXin Li #error Bad 10*67e74705SXin Li #endif 11*67e74705SXin Li 12*67e74705SXin Li #if !__has_builtin(__builtin_huge_val) || \ 13*67e74705SXin Li !__has_builtin(__builtin_shufflevector) || \ 14*67e74705SXin Li !__has_builtin(__builtin_convertvector) || \ 15*67e74705SXin Li !__has_builtin(__builtin_trap) || \ 16*67e74705SXin Li !__has_builtin(__c11_atomic_init) || \ 17*67e74705SXin Li !__has_feature(attribute_analyzer_noreturn) || \ 18*67e74705SXin Li !__has_feature(attribute_overloadable) 19*67e74705SXin Li #error Clang should have these 20*67e74705SXin Li #endif 21*67e74705SXin Li 22*67e74705SXin Li #if __has_builtin(__builtin_insanity) 23*67e74705SXin Li #error Clang should not have this 24*67e74705SXin Li #endif 25*67e74705SXin Li 26*67e74705SXin Li #if !__has_feature(__attribute_deprecated_with_message__) 27*67e74705SXin Li #error Feature name in double underscores does not work 28*67e74705SXin Li #endif 29*67e74705SXin Li 30*67e74705SXin Li // Make sure we have x86 builtins only (forced with target triple). 31*67e74705SXin Li 32*67e74705SXin Li #if !__has_builtin(__builtin_ia32_emms) || \ 33*67e74705SXin Li __has_builtin(__builtin_altivec_abs_v4sf) 34*67e74705SXin Li #error Broken handling of target-specific builtins 35*67e74705SXin Li #endif 36*67e74705SXin Li 37*67e74705SXin Li // Macro expansion does not occur in the parameter to __has_builtin, 38*67e74705SXin Li // __has_feature, etc. (as is also expected behaviour for ordinary 39*67e74705SXin Li // macros), so the following should not expand: 40*67e74705SXin Li 41*67e74705SXin Li #define MY_ALIAS_BUILTIN __c11_atomic_init 42*67e74705SXin Li #define MY_ALIAS_FEATURE attribute_overloadable 43*67e74705SXin Li 44*67e74705SXin Li #if __has_builtin(MY_ALIAS_BUILTIN) || __has_feature(MY_ALIAS_FEATURE) 45*67e74705SXin Li #error Alias expansion not allowed 46*67e74705SXin Li #endif 47*67e74705SXin Li 48*67e74705SXin Li // But deferring should expand: 49*67e74705SXin Li 50*67e74705SXin Li #define HAS_BUILTIN(X) __has_builtin(X) 51*67e74705SXin Li #define HAS_FEATURE(X) __has_feature(X) 52*67e74705SXin Li 53*67e74705SXin Li #if !HAS_BUILTIN(MY_ALIAS_BUILTIN) || !HAS_FEATURE(MY_ALIAS_FEATURE) 54*67e74705SXin Li #error Expansion should have occurred 55*67e74705SXin Li #endif 56*67e74705SXin Li 57*67e74705SXin Li #ifdef VERIFY 58*67e74705SXin Li // expected-error@+1 {{builtin feature check macro requires a parenthesized identifier}} 59*67e74705SXin Li #if __has_feature('x') 60*67e74705SXin Li #endif 61*67e74705SXin Li 62*67e74705SXin Li // The following are not identifiers: 63*67e74705SXin Li _Static_assert(!__is_identifier("string"), "oops"); 64*67e74705SXin Li _Static_assert(!__is_identifier('c'), "oops"); 65*67e74705SXin Li _Static_assert(!__is_identifier(123), "oops"); 66*67e74705SXin Li _Static_assert(!__is_identifier(int), "oops"); 67*67e74705SXin Li 68*67e74705SXin Li // The following are: 69*67e74705SXin Li _Static_assert(__is_identifier(abc /* comment */), "oops"); 70*67e74705SXin Li _Static_assert(__is_identifier /* comment */ (xyz), "oops"); 71*67e74705SXin Li 72*67e74705SXin Li // expected-error@+1 {{too few arguments}} 73*67e74705SXin Li #if __is_identifier() 74*67e74705SXin Li #endif 75*67e74705SXin Li 76*67e74705SXin Li // expected-error@+1 {{too many arguments}} 77*67e74705SXin Li #if __is_identifier(,()) 78*67e74705SXin Li #endif 79*67e74705SXin Li 80*67e74705SXin Li // expected-error@+1 {{missing ')' after 'abc'}} 81*67e74705SXin Li #if __is_identifier(abc xyz) // expected-note {{to match this '('}} 82*67e74705SXin Li #endif 83*67e74705SXin Li 84*67e74705SXin Li // expected-error@+1 {{missing ')' after 'abc'}} 85*67e74705SXin Li #if __is_identifier(abc()) // expected-note {{to match this '('}} 86*67e74705SXin Li #endif 87*67e74705SXin Li 88*67e74705SXin Li // expected-error@+1 {{missing ')' after '.'}} 89*67e74705SXin Li #if __is_identifier(.abc) // expected-note {{to match this '('}} 90*67e74705SXin Li #endif 91*67e74705SXin Li 92*67e74705SXin Li // expected-error@+1 {{nested parentheses not permitted in '__is_identifier'}} 93*67e74705SXin Li #if __is_identifier((abc)) 94*67e74705SXin Li #endif 95*67e74705SXin Li 96*67e74705SXin Li // expected-error@+1 {{missing '(' after '__is_identifier'}} expected-error@+1 {{expected value}} 97*67e74705SXin Li #if __is_identifier 98*67e74705SXin Li #endif 99*67e74705SXin Li 100*67e74705SXin Li // expected-error@+1 {{unterminated}} expected-error@+1 {{expected value}} 101*67e74705SXin Li #if __is_identifier( 102*67e74705SXin Li #endif 103*67e74705SXin Li 104*67e74705SXin Li #endif 105