cmList: Use ptrdiff_t for index_type

In commit 87fe031a07 (cmList class: various enhancements, 2023-04-26,
v3.27.0-rc1~142^2~1) this changed from `int` to `intptr_t`, but on some
systems (e.g. CHERI-enabled Arm or RISC-V), `intptr_t` is larger than 64
bits and using it for `index_type` here incurs an unnecessary
performance penalty.  Additionally, using `intptr_t` here results in an
ambiguous overload while calling `cmStrCat` with `intptr_t`: `error:
conversion from '__intcap' to 'const cmAlphaNum' is ambiguous`.

Instead of adding `intptr_t` overloads for `cmAlphaNum` for CHERI
systems, we can change the type to `ptrdiff_t` (which will be the same
as `intptr_t` on all other systems) and avoid carrying diffs that only
compile with a CHERI enabled compiler.
This commit is contained in:
Alex Richardson
2024-03-03 22:22:07 -08:00
committed by Brad King
parent debf777290
commit e563201f9e

View File

@@ -6,7 +6,7 @@
#include "cmConfigure.h" // IWYU pragma: keep
#include <algorithm>
#include <cstdint>
#include <cstddef>
#include <initializer_list>
#include <iterator>
#include <memory>
@@ -47,7 +47,7 @@ public:
using value_type = container_type::value_type;
using allocator_type = container_type::allocator_type;
using index_type = std::intptr_t;
using index_type = std::ptrdiff_t;
using size_type = container_type::size_type;
using difference_type = container_type::difference_type;
using reference = container_type::reference;