[libc++] Avoid creating temporaries in unary expressions involving valarray
authorLouis Dionne <ldionne.2@gmail.com>
Thu, 5 May 2022 16:24:43 +0000 (12:24 -0400)
committerLouis Dionne <ldionne.2@gmail.com>
Mon, 6 Jun 2022 16:58:23 +0000 (12:58 -0400)
commitb8f6f9e741c60a06cbe14adf890db0889b3b333f
tree5b2af47dd06dd4352f91a81b26307b035eace9ac
parent04d4130a513783eecbec426c8151c1d2fe086430
[libc++] Avoid creating temporaries in unary expressions involving valarray

Currently, unary expressions involving valarray will create a temporary.
This leads to dangling references in expressions like `-a * b`, because
`-a` is a temporary and the resulting expression will refer to it. This
patch fixes the problem by creating a lazy expression to perform the unary
operation instead of eagerly creating a temporary valarray. This is
permitted by the Standard, which does not specify the exact type of
most expressions involving valarrays.

This is technically an ABI break, however I believe the actual potential
for breakage is very low.

rdar://90152242

Differential Revision: https://reviews.llvm.org/D125019
libcxx/docs/ReleaseNotes.rst
libcxx/include/valarray
libcxx/test/std/numerics/numarray/template.valarray/valarray.unary/bit_not.pass.cpp
libcxx/test/std/numerics/numarray/template.valarray/valarray.unary/negate.pass.cpp
libcxx/test/std/numerics/numarray/template.valarray/valarray.unary/not.pass.cpp
libcxx/test/std/numerics/numarray/template.valarray/valarray.unary/plus.pass.cpp