diff options
| author | Léo Lam <leo@leolam.fr> | 2022-07-01 16:57:40 +0200 |
|---|---|---|
| committer | Léo Lam <leo@leolam.fr> | 2022-07-01 17:01:40 +0200 |
| commit | 0912686d9b4a41fed203215be63f348161dc5e6e (patch) | |
| tree | 71a5221920f3e9b3c51ae1a156bc425e1b2a4410 | |
| parent | bd8b3dc61d1cb60fd66554b826d91f4b0d75dda5 (diff) | |
IteratorUtil: Forward (non-reference) return types correctly
With auto&, an operator[] that returns a value (and not a reference)
would result in the proxy returning a reference to a local temporary,
which is UB
| -rw-r--r-- | src/KingSystem/Utils/IteratorUtil.h | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/KingSystem/Utils/IteratorUtil.h b/src/KingSystem/Utils/IteratorUtil.h index 3058201b..aa64b5a8 100644 --- a/src/KingSystem/Utils/IteratorUtil.h +++ b/src/KingSystem/Utils/IteratorUtil.h @@ -66,8 +66,8 @@ public: : mIndex(index), mContainer(container) {} int getIndex() const { return mIndex; } - constexpr auto& get() const { return mContainer[mIndex]; } - constexpr auto& operator*() const { return get(); } + constexpr decltype(auto) get() const { return mContainer[mIndex]; } + constexpr decltype(auto) operator*() const { return get(); } constexpr auto* operator->() const { return &get(); } private: |
