Skip to content

Commit 62c6887

Browse files
committed
GH-42536: [C++] Replace std::aligned_storage that is deprecated in C++23
Fixes #41536
1 parent a1627b9 commit 62c6887

File tree

2 files changed

+1
-35
lines changed

2 files changed

+1
-35
lines changed

cpp/cmake_modules/SetupCxxFlags.cmake

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -163,21 +163,6 @@ if(WIN32)
163163
# insecure, like std::getenv
164164
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
165165

166-
# Disable static assertion in Microsoft C++ standard library.
167-
#
168-
# """[...]\include\type_traits(1271): error C2338:
169-
# You've instantiated std::aligned_storage<Len, Align> with an extended
170-
# alignment (in other words, Align > alignof(max_align_t)).
171-
# Before VS 2017 15.8, the member type would non-conformingly have an
172-
# alignment of only alignof(max_align_t). VS 2017 15.8 was fixed to handle
173-
# this correctly, but the fix inherently changes layout and breaks binary
174-
# compatibility (*only* for uses of aligned_storage with extended alignments).
175-
# Please define either (1) _ENABLE_EXTENDED_ALIGNED_STORAGE to acknowledge
176-
# that you understand this message and that you actually want a type with
177-
# an extended alignment, or (2) _DISABLE_EXTENDED_ALIGNED_STORAGE to silence
178-
# this message and get the old non-conformant behavior."""
179-
add_definitions(-D_ENABLE_EXTENDED_ALIGNED_STORAGE)
180-
181166
if(MSVC)
182167
# ARROW-1931 See https://github.com/google/googletest/issues/1318
183168
#

cpp/src/arrow/util/aligned_storage.h

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -119,26 +119,7 @@ class AlignedStorage {
119119
}
120120

121121
private:
122-
#if !defined(__clang__) && defined(__GNUC__) && defined(__i386__)
123-
// Workaround for GCC bug on i386:
124-
// alignof(int64 | float64) can give different results depending on the
125-
// compilation context, leading to internal ABI mismatch manifesting
126-
// in incorrect propagation of Result<int64 | float64> between
127-
// compilation units.
128-
// (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88115)
129-
static constexpr size_t alignment() {
130-
if (std::is_integral_v<T> && sizeof(T) == 8) {
131-
return 4;
132-
} else if (std::is_floating_point_v<T> && sizeof(T) == 8) {
133-
return 4;
134-
}
135-
return alignof(T);
136-
}
137-
138-
typename std::aligned_storage<sizeof(T), alignment()>::type data_;
139-
#else
140-
typename std::aligned_storage<sizeof(T), alignof(T)>::type data_;
141-
#endif
122+
alignas(T) std::byte data_[sizeof(T)];
142123
};
143124

144125
} // namespace internal

0 commit comments

Comments
 (0)