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