1 // RUN: %clang_cc1 -fsyntax-only -verify=expected,cxx14 -std=c++14 %s
2 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++2a %s
4 typedef __SIZE_TYPE__
size_t;
7 // Ensuring that __bos can be used in constexpr functions without anything
12 return __builtin_object_size(&cs
[k
], 0);
15 constexpr int bos1() {
18 return __builtin_object_size(&cs
[k
], 1);
21 constexpr int bos2() {
24 return __builtin_object_size(&cs
[k
], 2);
27 constexpr int bos3() {
30 return __builtin_object_size(&cs
[k
], 3);
33 static_assert(bos0() == sizeof(char) * 5, "");
34 static_assert(bos1() == sizeof(char) * 5, "");
35 static_assert(bos2() == sizeof(char) * 5, "");
36 static_assert(bos3() == sizeof(char) * 5, "");
39 namespace in_enable_if
{
40 // The code that prompted these changes was __bos in enable_if
42 void copy5CharsInto(char *buf
) // expected-note{{candidate}}
43 __attribute__((enable_if(__builtin_object_size(buf
, 0) != -1 &&
44 __builtin_object_size(buf
, 0) > 5,
47 // We use different EvalModes for __bos with type 0 versus 1. Ensure 1 works,
49 void copy5CharsIntoStrict(char *buf
) // expected-note{{candidate}}
50 __attribute__((enable_if(__builtin_object_size(buf
, 1) != -1 &&
51 __builtin_object_size(buf
, 1) > 5,
71 copy5CharsIntoStrict(large
.buf
);
78 LargeStruct large
= {0, {}, 0};
79 copy5CharsIntoStrict(large
.buf
);
83 void initTheBufWithALoop() {
85 for (unsigned I
= getI(); I
!= sizeof(buf
); ++I
)
90 for (unsigned I
= getI(); I
!= sizeof(buf
); ++I
)
92 copy5CharsIntoStrict(large
.buf
);
97 copy5CharsInto(buf
); // expected-error{{no matching function for call}}
100 copy5CharsIntoStrict(small
.buf
); // expected-error{{no matching function for call}}
104 namespace InvalidBase
{
105 // Ensure this doesn't crash.
106 struct S
{ const char *name
; };
108 constexpr size_t bos_name
= __builtin_object_size(invalid_base().name
, 1);
109 static_assert(bos_name
== -1, "");
113 constexpr size_t bos_dtor
= __builtin_object_size(&(T
&)(T
&&)invalid_base_2(), 0);
114 static_assert(bos_dtor
== -1, "");
118 constexpr int bos_new() { // cxx14-error {{constant expression}}
119 void *p
= new int; // cxx14-note {{until C++20}}
120 return __builtin_object_size(p
, 0);