[llvm] [LLVM][ADT] Explicitly convert size_t values to SmallVector's size type (PR #77939)
Andrew Browne via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 12 10:27:34 PST 2024
================
@@ -99,8 +99,9 @@ template <class Size_T> class SmallVectorBase {
///
/// This does not construct or destroy any elements in the vector.
void set_size(size_t N) {
- assert(N <= capacity());
- Size = N;
+ auto n = static_cast<Size_T>(N);
+ assert(n <= capacity());
----------------
browneee wrote:
`capacity()` also returns `size_t`, so probably better to keep the assertion first. e.g.
```
assert(N <= capacity());
Size = static_cast<Size_T>(N);
// As Felipe suggests, you could add:
assert(static_cast<size_t>(Size) == N);
```
https://github.com/llvm/llvm-project/pull/77939
More information about the llvm-commits
mailing list