[libcxx-commits] [PATCH] D125019: [libc++] Avoid creating temporaries in unary expressions involving valarray

Louis Dionne via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Thu May 5 09:32:48 PDT 2022


ldionne created this revision.
Herald added a project: All.
ldionne requested review of this revision.
Herald added a project: libc++.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.

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.

rdar://90152242


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D125019

Files:
  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

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D125019.427356.patch
Type: text/x-patch
Size: 6110 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20220505/9770ec0a/attachment.bin>


More information about the libcxx-commits mailing list