Merge pull request #239 from dangelog/issue238

Do not memset(0) POD types
This commit is contained in:
Ion Gaztañaga
2023-02-13 08:54:03 +01:00
committed by GitHub
3 changed files with 25 additions and 7 deletions

View File

@@ -1276,10 +1276,6 @@ member object and member function pointers) to be initializable using `std::mems
Most platforms are compatible with this initialization, but in case this initialization is not desired the
user can `#define BOOST_CONTAINER_MEMZEROED_POINTER_IS_NOT_ZERO` before including library headers.
If neither `BOOST_CONTAINER_MEMZEROED_FLOATING_POINT_IS_NOT_ZERO` nor
`BOOST_CONTAINER_MEMZEROED_POINTER_IS_NOT_ZERO` is defined [*Boost.Container] also considers POD
types to be value initializable via `std::memset` with value zero.
[endsect]
[endsect]

View File

@@ -296,9 +296,6 @@ struct is_memzero_initializable
#if defined(BOOST_CONTAINER_MEMZEROED_FLOATING_POINT_IS_ZERO)
|| dtl::is_floating_point<value_type>::value
#endif
#if defined(BOOST_CONTAINER_MEMZEROED_FLOATING_POINT_IS_ZERO) && defined(BOOST_CONTAINER_MEMZEROED_POINTER_IS_NULL)
|| dtl::is_pod<value_type>::value
#endif
);
};

View File

@@ -220,6 +220,12 @@ bool test_span_conversion()
#endif //BOOST_VECTOR_TEST_HAS_SPAN
struct POD { int POD::*ptr; };
BOOST_STATIC_ASSERT_MSG
( boost::container::dtl::is_pod<POD>::value
, "POD test failed"
);
int main()
{
{
@@ -392,5 +398,24 @@ int main()
);
}
////////////////////////////////////
// POD types should not be 0-filled testing
////////////////////////////////////
#if !defined(_MSC_VER)
// MSVC miscompiles value initialization of pointers to data members,
// https://developercommunity.visualstudio.com/t/Pointer-to-data-member-is-not-initialize/10238905
{
typedef boost::container::vector<POD> cont;
const std::size_t size = 10;
cont a(size);
for(std::size_t i = 0; i != size; ++i) {
if (a[i].ptr != 0) {
std::cerr << "POD test failed" << std::endl;
return 1;
}
}
}
#endif
return 0;
}