[libcxx-commits] [PATCH] D103371: [libc++] Avoid `result_type` and `unary/binary_function` in <valarray>

Arthur O'Dwyer via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Sun May 30 11:45:53 PDT 2021


Quuxplusone added a comment.

Buildkite is happy with this: https://buildkite.com/llvm-project/libcxx-ci/builds/3467



================
Comment at: libcxx/include/valarray:447
     _LIBCPP_INLINE_VISIBILITY
     value_type operator[](size_t __i) const {return __op_(__a0_[__i], __a1_[__i]);}
 
----------------
Quuxplusone wrote:
> Btw, I was surprised to find `value_type` here instead of `result_type`. But changing it (or even trying to produce a test case where the difference was observable) seemed like a rabbit hole, so I avoided it.
Today I think I've convinced myself that it doesn't matter: `_Op::__result_type` is always either `_Tp` or `bool`, and we only ever use `_BinaryOp` in type-expressions like `__val_expr<_BinaryOp<...>>`, and `__val_expr::operator[](size_t)` //does// correctly return `__result_type`; so at worst we're taking a `bool`, accidentally casting it up to `_Tp` here in `_BinaryOp::operator[]`, and then casting it back down to `bool` in `__val_expr::operator[]`. I don't think this is ever observable.

So I could "fix" this, or leave it as-is; either way it wouldn't be observable.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D103371/new/

https://reviews.llvm.org/D103371



More information about the libcxx-commits mailing list