[libcxx-commits] [PATCH] D69466: Guard against overflow in span::subspan
Michael Schellenberger Costa via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Wed Dec 18 02:12:27 PST 2019
miscco added a comment.
Scrap my comment about invalid access to an empty span. Adding a static assert to `operator[]` fails due to evaulation of both branches during compilation:
cpp
if (s.empty())
{
ret = ret && ( b == s.end());
ret = ret && (cb == s.cend());
}
else
{
ret = ret && ( *b == s[0]);
ret = ret && ( &*b == &s[0]);
ret = ret && ( *cb == s[0]);
ret = ret && (&*cb == &s[0]);
}
The code in question is obviously correct. So I guess one would need to guard such checks with `if (!std::is_constant_evaluated())` which seems a bit over the top.
Otherwise, I would need to revert the static_asserts in `front()` and `back()` as they would also trigger in a similar case.
Thoughts?
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D69466/new/
https://reviews.llvm.org/D69466
More information about the libcxx-commits
mailing list