From: Jakub Jelinek Date: Thu, 16 Jan 2025 08:17:50 +0000 (+0100) Subject: vec.h: Properly destruct elements in auto_vec auto storage [PR118400] X-Git-Tag: releases/gcc-14.3.0~515 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0faffd526d5dbed4960ef0aadc4ba96f9bf377de;p=thirdparty%2Fgcc.git vec.h: Properly destruct elements in auto_vec auto storage [PR118400] For T with non-trivial destructors, we were destructing objects in the vector on release only when not using auto storage of auto_vec. The following patch calls truncate (0) instead of m_vecpfx.m_num clearing, and truncate takes care of that destruction: unsigned l = length (); gcc_checking_assert (l >= size); if (!std::is_trivially_destructible ::value) vec_destruct (address () + size, l - size); m_vecpfx.m_num = size; 2025-01-16 Jakub Jelinek PR ipa/118400 * vec.h (vec::release): Call m_vec->truncate (0) instead of clearing m_vec->m_vecpfx.m_num. (cherry picked from commit 43f4d44bebd63b354f8798fcef512d4d2b42c655) --- diff --git a/gcc/vec.h b/gcc/vec.h index bc83827f644..84540d4802e 100644 --- a/gcc/vec.h +++ b/gcc/vec.h @@ -2020,7 +2020,7 @@ vec::release (void) if (using_auto_storage ()) { - m_vec->m_vecpfx.m_num = 0; + m_vec->truncate (0); return; }