Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-41536: [C++] Replace std::aligned_storage that is deprecated in C++23 #45019

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions cpp/cmake_modules/SetupCxxFlags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -163,21 +163,6 @@ if(WIN32)
# insecure, like std::getenv
add_definitions(-D_CRT_SECURE_NO_WARNINGS)

# Disable static assertion in Microsoft C++ standard library.
#
# """[...]\include\type_traits(1271): error C2338:
# You've instantiated std::aligned_storage<Len, Align> with an extended
# alignment (in other words, Align > alignof(max_align_t)).
# Before VS 2017 15.8, the member type would non-conformingly have an
# alignment of only alignof(max_align_t). VS 2017 15.8 was fixed to handle
# this correctly, but the fix inherently changes layout and breaks binary
# compatibility (*only* for uses of aligned_storage with extended alignments).
# Please define either (1) _ENABLE_EXTENDED_ALIGNED_STORAGE to acknowledge
# that you understand this message and that you actually want a type with
# an extended alignment, or (2) _DISABLE_EXTENDED_ALIGNED_STORAGE to silence
# this message and get the old non-conformant behavior."""
add_definitions(-D_ENABLE_EXTENDED_ALIGNED_STORAGE)

if(MSVC)
# ARROW-1931 See https://github.com/google/googletest/issues/1318
#
Expand Down
21 changes: 1 addition & 20 deletions cpp/src/arrow/util/aligned_storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,26 +119,7 @@ class AlignedStorage {
}

private:
#if !defined(__clang__) && defined(__GNUC__) && defined(__i386__)
// Workaround for GCC bug on i386:
// alignof(int64 | float64) can give different results depending on the
// compilation context, leading to internal ABI mismatch manifesting
// in incorrect propagation of Result<int64 | float64> between
// compilation units.
// (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88115)
static constexpr size_t alignment() {
if (std::is_integral_v<T> && sizeof(T) == 8) {
return 4;
} else if (std::is_floating_point_v<T> && sizeof(T) == 8) {
return 4;
}
return alignof(T);
}

typename std::aligned_storage<sizeof(T), alignment()>::type data_;
#else
typename std::aligned_storage<sizeof(T), alignof(T)>::type data_;
#endif
alignas(T) std::byte data_[sizeof(T)];
};

} // namespace internal
Expand Down
Loading