[all-commits] [llvm/llvm-project] 40a6be: [libc++] Ensure valid view for view_interface temp...
Joseph Loser via All-commits
all-commits at lists.llvm.org
Fri Oct 29 16:12:53 PDT 2021
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 40a6be4346097c008998d702381b07acbc6c9ae2
https://github.com/llvm/llvm-project/commit/40a6be4346097c008998d702381b07acbc6c9ae2
Author: Joe Loser <joeloser93 at gmail.com>
Date: 2021-10-29 (Fri, 29 Oct 2021)
Changed paths:
M libcxx/include/__ranges/view_interface.h
Log Message:
-----------
[libc++] Ensure valid view for view_interface template parameter
Some types that inherit from `view_interface` do not meet the
preconditions. This came up during discussion
in https://reviews.llvm.org/D112631. Currently, the behavior is IFNDR,
but the preconditions can be easily checked, so let's do so.
In particular, we know each public member function calls the
`__derived()` private function, so we can do the check there. We
intentionally do it as a `static_assert` instead of a `requires` clause
to avoid hard erroring in some cases, such as with incomplete types. An
example hard error is:
```
llvm-project/build/include/c++/v1/__ranges/view_interface.h:48:14: note: because 'sizeof(_Tp)' would be invalid: invalid application of 'sizeof' to an incomplete type 'MoveOnlyForwardRange'
requires { sizeof(_Tp); } &&
^
llvm-project/build/include/c++/v1/__ranges/view_interface.h:73:26: error: no matching member function for call to '__derived'
return ranges::begin(__derived()) == ranges::end(__derived());
^~~~~~~~~
llvm-project/libcxx/test/std/ranges/range.utility/view.interface/view.interface.pass.cpp:187:31: note: in instantiation of function template specialization 'std::ranges::view_interface<MoveOnlyForwardRange>::empty<Mov
eOnlyForwardRange>' requested here
assert(!std::move(moveOnly).empty());
```
Reviewed By: Quuxplusone, Mordante, #libc
Differential Revision: https://reviews.llvm.org/D112665
More information about the All-commits
mailing list