Remove UB with proper conditional

This commit is contained in:
ThePhD 2020-11-20 17:07:24 -05:00
parent 1b49f3ec43
commit bd09f8e853
No known key found for this signature in database
GPG Key ID: 1509DB1C0F702BFA

View File

@ -104,7 +104,7 @@ namespace sol {
std::size_t aligned_space_for(void* alignment = nullptr) { std::size_t aligned_space_for(void* alignment = nullptr) {
// use temporary storage to prevent strict UB shenanigans // use temporary storage to prevent strict UB shenanigans
char alignment_shim[(std::max)({ sizeof(Args)... }) + (std::max)({ alignof(Args)... })] {}; char alignment_shim[(std::max)({ sizeof(Args)... }) + (std::max)({ alignof(Args)... })] {};
char* start = alignment == nullptr ? static_cast<char*>(alignment) : alignment_shim; char* start = alignment != nullptr ? static_cast<char*>(alignment) : alignment_shim;
(void)detail::swallow { int {}, (align_one(std::alignment_of_v<Args>, sizeof(Args), alignment), int {})... }; (void)detail::swallow { int {}, (align_one(std::alignment_of_v<Args>, sizeof(Args), alignment), int {})... };
return static_cast<char*>(alignment) - start; return static_cast<char*>(alignment) - start;
} }