https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99117

--- Comment #24 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-13 branch has been updated by Jonathan Wakely
<r...@gcc.gnu.org>:

https://gcc.gnu.org/g:3a72c717b311ce8093042d927a1f2f2b940a969c

commit r13-8334-g3a72c717b311ce8093042d927a1f2f2b940a969c
Author: Jonathan Wakely <jwak...@redhat.com>
Date:   Thu Feb 8 13:59:42 2024 +0000

    libstdc++: Avoid aliasing violation in std::valarray [PR99117]

    The call to __valarray_copy constructs an _Array object to refer to
    this->_M_data but that means that accesses to this->_M_data are through
    a restrict-qualified pointer. This leads to undefined behaviour when
    copying from an _Expr object that actually aliases this->_M_data.

    Replace the call to __valarray_copy with a plain loop. I think this
    removes the only use of that overload of __valarray_copy, so it could
    probably be removed. I haven't done that here.

    libstdc++-v3/ChangeLog:

            PR libstdc++/99117
            * include/std/valarray (valarray::operator=(const _Expr&)):
            Use loop to copy instead of __valarray_copy with _Array.
            * testsuite/26_numerics/valarray/99117.cc: New test.

    (cherry picked from commit b58f0e5216a3053486e7f1aa96c3f2443b14d630)

Reply via email to