[libcxx-commits] [libcxx] [libc++] P3168R2 Give std::optional Range Support (PR #146491)
Yanzuo Liu via libcxx-commits
libcxx-commits at lists.llvm.org
Tue Jul 1 05:10:07 PDT 2025
zwuis wrote:
> ```c++
> _LIBCPP_HIDE_FROM_ABI constexpr reference operator*() const {
> if (__ptr_ == nullptr)
> std::__throw_runtime_error("deferencering end iterator");
> return *__ptr_;
> }
>
> _LIBCPP_HIDE_FROM_ABI constexpr pointer operator->() const {
> if (__ptr_ == nullptr)
> std::__throw_runtime_error("deferencering end iterator");
> return *__ptr_;
> }
> ```
>
> Should these functions return `__ptr_` instead of throwing exceptions if `__ptr_` is nullptr? Throwing exceptions is not allowed in constexpr functions
`*end()` is UB so this `if` statement should be removed.
https://github.com/llvm/llvm-project/pull/146491
More information about the libcxx-commits
mailing list