Skip to content

Commit 0334915

Browse files
committed
Fix Clang deprecated builtins
It seems that Clang and GCC have different interpretations of certain builtins. So this PR fixes the "deprecated" builtins for Clang, but keeps them for GCC.
1 parent df55005 commit 0334915

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

include/godot_cpp/templates/cowdata.hpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,11 @@ void CowData<T>::_unref(void *p_data) {
212212
}
213213
// clean up
214214

215+
#ifdef __clang__
216+
if (!__is_trivially_destructible(T)) {
217+
#else
215218
if (!__has_trivial_destructor(T)) {
219+
#endif
216220
uint32_t *count = _get_size();
217221
T *data = (T *)(count + 1);
218222

@@ -247,7 +251,11 @@ uint32_t CowData<T>::_copy_on_write() {
247251
T *_data = (T *)(mem_new);
248252

249253
// initialize new elements
254+
#ifdef __clang__
255+
if (__is_trivially_copyable(T)) {
256+
#else
250257
if (__has_trivial_copy(T)) {
258+
#endif
251259
memcpy(mem_new, _ptr, current_size * sizeof(T));
252260

253261
} else {
@@ -310,7 +318,11 @@ Error CowData<T>::resize(int p_size) {
310318

311319
// construct the newly created elements
312320

321+
#ifdef __clang__
322+
if (!__is_trivially_constructible(T)) {
323+
#else
313324
if (!__has_trivial_constructor(T)) {
325+
#endif
314326
T *elems = _get_data();
315327

316328
for (int i = *_get_size(); i < p_size; i++) {
@@ -321,7 +333,11 @@ Error CowData<T>::resize(int p_size) {
321333
*_get_size() = p_size;
322334

323335
} else if (p_size < current_size) {
336+
#ifdef __clang__
337+
if (!__is_trivially_destructible(T)) {
338+
#else
324339
if (!__has_trivial_destructor(T)) {
340+
#endif
325341
// deinitialize no longer needed elements
326342
for (uint32_t i = p_size; i < *_get_size(); i++) {
327343
T *t = &_get_data()[i];

0 commit comments

Comments
 (0)