xref: /aosp_15_r20/external/clang/test/SemaCXX/builtins.cpp (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li // RUN: %clang_cc1 %s -fsyntax-only -verify -std=c++11
2*67e74705SXin Li typedef const struct __CFString * CFStringRef;
3*67e74705SXin Li #define CFSTR __builtin___CFStringMakeConstantString
4*67e74705SXin Li 
f()5*67e74705SXin Li void f() {
6*67e74705SXin Li   (void)CFStringRef(CFSTR("Hello"));
7*67e74705SXin Li }
8*67e74705SXin Li 
a()9*67e74705SXin Li void a() { __builtin_va_list x, y; ::__builtin_va_copy(x, y); }
10*67e74705SXin Li 
11*67e74705SXin Li // <rdar://problem/10063539>
12*67e74705SXin Li template<int (*Compare)(const char *s1, const char *s2)>
equal(const char * s1,const char * s2)13*67e74705SXin Li int equal(const char *s1, const char *s2) {
14*67e74705SXin Li   return Compare(s1, s2) == 0;
15*67e74705SXin Li }
16*67e74705SXin Li // FIXME: Our error recovery here sucks
17*67e74705SXin Li template int equal<&__builtin_strcmp>(const char*, const char*); // expected-error {{builtin functions must be directly called}} expected-error {{expected unqualified-id}} expected-error {{expected ')'}} expected-note {{to match this '('}}
18*67e74705SXin Li 
19*67e74705SXin Li // PR13195
f2()20*67e74705SXin Li void f2() {
21*67e74705SXin Li   __builtin_isnan; // expected-error {{builtin functions must be directly called}}
22*67e74705SXin Li }
23*67e74705SXin Li 
24*67e74705SXin Li // pr14895
25*67e74705SXin Li typedef __typeof(sizeof(int)) size_t;
26*67e74705SXin Li extern "C" void *__builtin_alloca (size_t);
27*67e74705SXin Li 
28*67e74705SXin Li namespace addressof {
29*67e74705SXin Li   struct S {} s;
30*67e74705SXin Li   static_assert(__builtin_addressof(s) == &s, "");
31*67e74705SXin Li 
operator &addressof::T32*67e74705SXin Li   struct T { constexpr T *operator&() const { return nullptr; } int n; } t;
33*67e74705SXin Li   constexpr T *pt = __builtin_addressof(t);
34*67e74705SXin Li   static_assert(&pt->n == &t.n, "");
35*67e74705SXin Li 
36*67e74705SXin Li   struct U { int n : 5; } u;
37*67e74705SXin Li   int *pbf = __builtin_addressof(u.n); // expected-error {{address of bit-field requested}}
38*67e74705SXin Li 
39*67e74705SXin Li   S *ptmp = __builtin_addressof(S{}); // expected-error {{taking the address of a temporary}}
40*67e74705SXin Li }
41*67e74705SXin Li 
no_ms_builtins()42*67e74705SXin Li void no_ms_builtins() {
43*67e74705SXin Li   __assume(1); // expected-error {{use of undeclared}}
44*67e74705SXin Li   __noop(1); // expected-error {{use of undeclared}}
45*67e74705SXin Li   __debugbreak(); // expected-error {{use of undeclared}}
46*67e74705SXin Li }
47