BinomialLLC / basis_universal

Basis Universal GPU Texture Codec
Apache License 2.0
2.72k stars 267 forks source link

Allow defining BASISU_HAVE_STD_TRIVIALLY_COPYABLE #325

Closed past-due closed 1 year ago

past-due commented 2 years ago

To force std::is_trivially_copyable.

Allows the library consumer to resolve issues with some build environments (for example, Clang-based build environments) that may actually provide std::is_trivially_copyable but may also define __GNUC__ (< 5).

The latest versions of Clang (Clang 15+) may trigger a warning / error without this, as they have deprecated __has_trivial_copy and will throw -Wdeprecated-builtins @richgel999

Example:

Error: .../transcoder/basisu_containers.h:745:19: error: builtin __has_trivial_copy is deprecated; use __is_trivially_copyable instead [-Werror,-Wdeprecated-builtins]
            if ((!BASISU_IS_BITWISE_COPYABLE(T)) || (BASISU_HAS_DESTRUCTOR(T)))
                  ^
.../transcoder/basisu_containers.h:198:88: note: expanded from macro 'BASISU_IS_BITWISE_COPYABLE'
#define BASISU_IS_BITWISE_COPYABLE(T) (BASISU_IS_SCALAR_TYPE(T) || BASISU_IS_POD(T) || BASISU_IS_TRIVIALLY_COPYABLE(T) || (bitwise_copyable<T>::cFlag))
                                                                                       ^
.../transcoder/basisu_containers.h:192:46: note: expanded from macro 'BASISU_IS_TRIVIALLY_COPYABLE'
   #define BASISU_IS_TRIVIALLY_COPYABLE(...) __has_trivial_copy(__VA_ARGS__)
past-due commented 1 year ago

@richgel999 What would be needed to get this (or a similar fix / workaround) upstreamed?

richgel999 commented 1 year ago

@richgel999 What would be needed to get this (or a similar fix / workaround) upstreamed?

Looks reasonable - merging it. Thank you!

dbs4261 commented 1 month ago

Hi, I'm updating my fork and came across this change. Is there any reason not to use __cplusplus < 201103L instead of !defined(BASISU_HAVE_STD_TRIVIALLY_COPYABLE)? The macro used in this patch would need to be defined manually, which is not explained in any of the documentation. std::is_trivially_copyable is part of the C++11 standard, so checking if the c++ standard library implementation supports at least the C++11 standard should be enough, right?