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