mirror of
https://github.com/ThePhD/sol2.git
synced 2024-03-22 13:10:44 +08:00
Remove UB with proper conditional
This commit is contained in:
parent
1b49f3ec43
commit
bd09f8e853
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user