From: David Wells Date: Sat, 7 Dec 2024 22:31:04 +0000 (-0500) Subject: AlignedVector: only use memset() with default-constructible types. X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=19294362e843bc18e4475558ade8d01e1fd3daf0;p=dealii.git AlignedVector: only use memset() with default-constructible types. This is slightly less restrictive than the present version. --- diff --git a/include/deal.II/base/aligned_vector.h b/include/deal.II/base/aligned_vector.h index b976df0829..4ee1522094 100644 --- a/include/deal.II/base/aligned_vector.h +++ b/include/deal.II/base/aligned_vector.h @@ -944,10 +944,10 @@ namespace internal return; Assert(destination != nullptr, ExcInternalError()); - // do not use memcmp for long double because on some systems it does not - // completely fill its memory and may lead to false positives in - // e.g. valgrind - if constexpr (std::is_trivial_v == true && + // do not use memcmp() for long double because on some systems it does not + // completely fill its memory and may lead to false positives in e.g. + // valgrind + if constexpr (std::is_trivially_default_constructible_v == true && std::is_same_v == false) { const unsigned char zero[sizeof(T)] = {}; @@ -967,8 +967,9 @@ namespace internal apply_to_subrange(const std::size_t begin, const std::size_t end) const override { - // Classes with trivial assignment of zero can use memset. - if constexpr (std::is_trivial_v == true) + // Only use memset() with types whose default constructors don't do + // anything. + if constexpr (std::is_trivially_default_constructible_v == true) if (trivial_element) { std::memset(destination_ + begin, 0, (end - begin) * sizeof(T)); @@ -1052,8 +1053,9 @@ namespace internal apply_to_subrange(const std::size_t begin, const std::size_t end) const override { - // Classes with trivial assignment of zero can use memset. - if constexpr (std::is_trivial_v == true) + // Only use memset() with types whose default constructors don't do + // anything. + if constexpr (std::is_trivially_default_constructible_v == true) std::memset(destination_ + begin, 0, (end - begin) * sizeof(T)); else default_construct_or_assign(begin,