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