[libcxx] r324194 - Fix initialization of array<const T, 0> with GCC.
Eric Fiselier via cfe-commits
cfe-commits at lists.llvm.org
Sun Feb 4 00:02:36 PST 2018
Author: ericwf
Date: Sun Feb 4 00:02:35 2018
New Revision: 324194
URL: http://llvm.org/viewvc/llvm-project?rev=324194&view=rev
Log:
Fix initialization of array<const T, 0> with GCC.
Previously, when handling zero-sized array of const objects we
used a const version of aligned_storage_t, which is not an array type.
However, GCC complains about initialization of the form: array<const T, 0> arr = {};
This patch fixes that bug by making the dummy object used to represent
the zero-sized array an array itself. This avoids GCC's complaints
about the uninitialized const member.
Modified:
libcxx/trunk/include/array
Modified: libcxx/trunk/include/array
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/array?rev=324194&r1=324193&r2=324194&view=diff
==============================================================================
--- libcxx/trunk/include/array (original)
+++ libcxx/trunk/include/array Sun Feb 4 00:02:35 2018
@@ -146,21 +146,19 @@ struct __array_traits {
template <class _Tp>
struct __array_traits<_Tp, 0> {
typedef typename aligned_storage<sizeof(_Tp), alignment_of<_Tp>::value>::type
- _NonConstStorageT;
+ _NonConstStorageT[1];
typedef typename conditional<is_const<_Tp>::value, const _NonConstStorageT,
_NonConstStorageT>::type _StorageT;
-
typedef typename remove_const<_Tp>::type _NonConstTp;
+
_LIBCPP_INLINE_VISIBILITY
- static _NonConstTp* __data(_NonConstStorageT& __store) {
- _StorageT *__ptr = std::addressof(__store);
- return reinterpret_cast<_NonConstTp*>(__ptr);
+ static _NonConstTp* __data(_NonConstStorageT &__store) {
+ return reinterpret_cast<_NonConstTp*>(__store);
}
_LIBCPP_INLINE_VISIBILITY
- static const _Tp* __data(const _StorageT& __store) {
- const _StorageT *__ptr = std::addressof(__store);
- return reinterpret_cast<const _Tp*>(__ptr);
+ static const _Tp* __data(const _StorageT &__store) {
+ return reinterpret_cast<const _Tp*>(__store);
}
_LIBCPP_INLINE_VISIBILITY
More information about the cfe-commits
mailing list