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 // These are technically implemented as keywords, but __has_builtin should 24 // still return true. 25 #if !__has_builtin(__builtin_LINE) || \ 26 !__has_builtin(__builtin_FILE) || \ 27 !__has_builtin(__builtin_FUNCTION) || \ 28 !__has_builtin(__builtin_COLUMN) 29 #error Clang should have these 30 #endif 31 32 #if __has_builtin(__builtin_insanity) 33 #error Clang should not have this 34 #endif 35 36 #if !__has_feature(__attribute_deprecated_with_message__) 37 #error Feature name in double underscores does not work 38 #endif 39 40 // Make sure we have x86 builtins only (forced with target triple). 41 42 #if !__has_builtin(__builtin_ia32_emms) || \ 43 __has_builtin(__builtin_altivec_abs_v4sf) 44 #error Broken handling of target-specific builtins 45 #endif 46 47 // Macro expansion does not occur in the parameter to __has_builtin, 48 // __has_feature, etc. (as is also expected behaviour for ordinary 49 // macros), so the following should not expand: 50 51 #define MY_ALIAS_BUILTIN __c11_atomic_init 52 #define MY_ALIAS_FEATURE attribute_overloadable 53 54 #if __has_builtin(MY_ALIAS_BUILTIN) || __has_feature(MY_ALIAS_FEATURE) 55 #error Alias expansion not allowed 56 #endif 57 58 // But deferring should expand: 59 60 #define HAS_BUILTIN(X) __has_builtin(X) 61 #define HAS_FEATURE(X) __has_feature(X) 62 63 #if !HAS_BUILTIN(MY_ALIAS_BUILTIN) || !HAS_FEATURE(MY_ALIAS_FEATURE) 64 #error Expansion should have occurred 65 #endif 66 67 #ifdef VERIFY 68 // expected-error@+1 {{builtin feature check macro requires a parenthesized identifier}} 69 #if __has_feature('x') 70 #endif 71 72 // The following are not identifiers: 73 _Static_assert(!__is_identifier("string"), "oops"); 74 _Static_assert(!__is_identifier('c'), "oops"); 75 _Static_assert(!__is_identifier(123), "oops"); 76 _Static_assert(!__is_identifier(int), "oops"); 77 78 // The following are: 79 _Static_assert(__is_identifier(abc /* comment */), "oops"); 80 _Static_assert(__is_identifier /* comment */ (xyz), "oops"); 81 82 // expected-error@+1 {{too few arguments}} 83 #if __is_identifier() 84 #endif 85 86 // expected-error@+1 {{too many arguments}} 87 #if __is_identifier(,()) 88 #endif 89 90 // expected-error@+1 {{missing ')' after 'abc'}} 91 #if __is_identifier(abc xyz) // expected-note {{to match this '('}} 92 #endif 93 94 // expected-error@+1 {{missing ')' after 'abc'}} 95 #if __is_identifier(abc()) // expected-note {{to match this '('}} 96 #endif 97 98 // expected-error@+1 {{missing ')' after '.'}} 99 #if __is_identifier(.abc) // expected-note {{to match this '('}} 100 #endif 101 102 // expected-error@+1 {{nested parentheses not permitted in '__is_identifier'}} 103 #if __is_identifier((abc)) 104 #endif 105 106 // expected-error@+1 {{missing '(' after '__is_identifier'}} expected-error@+1 {{expected value}} 107 #if __is_identifier 108 #endif 109 110 // expected-error@+1 {{unterminated}} expected-error@+1 {{expected value}} 111 #if __is_identifier( 112 #endif 113 114 #endif 115