Skip to content

Commit

Permalink
Fix Clang deprecated builtins
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
adamscott committed Aug 15, 2023
1 parent df55005 commit 0334915
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions include/godot_cpp/templates/cowdata.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,11 @@ void CowData<T>::_unref(void *p_data) {
}
// clean up

#ifdef __clang__
if (!__is_trivially_destructible(T)) {
#else
if (!__has_trivial_destructor(T)) {
#endif
uint32_t *count = _get_size();
T *data = (T *)(count + 1);

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

// initialize new elements
#ifdef __clang__
if (__is_trivially_copyable(T)) {
#else
if (__has_trivial_copy(T)) {
#endif
memcpy(mem_new, _ptr, current_size * sizeof(T));

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

// construct the newly created elements

#ifdef __clang__
if (!__is_trivially_constructible(T)) {
#else
if (!__has_trivial_constructor(T)) {
#endif
T *elems = _get_data();

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

} else if (p_size < current_size) {
#ifdef __clang__
if (!__is_trivially_destructible(T)) {
#else
if (!__has_trivial_destructor(T)) {
#endif
// deinitialize no longer needed elements
for (uint32_t i = p_size; i < *_get_size(); i++) {
T *t = &_get_data()[i];
Expand Down

0 comments on commit 0334915

Please sign in to comment.