Skip to content

Commit

Permalink
Fix RiegeliReset(T& dest, MakerTypeFor<T, Args...>&& src). It used
Browse files Browse the repository at this point in the history
`std::move(src.maker())` instead of `std::move(src).maker()`, which used the
`const&` overload of `maker()` because the `&&` overload was not applicable,
and could be inefficient, or break the build if `src` was movable but not
copyable.

Add `&` and `const&&` overloads to `maker()` accessor, which would also have
fixed this.

PiperOrigin-RevId: 684858583
  • Loading branch information
QrczakMK committed Oct 11, 2024
1 parent 4dddb9a commit 03a7e2e
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions riegeli/base/maker.h
Original file line number Diff line number Diff line change
Expand Up @@ -562,14 +562,16 @@ class MakerTypeForBase
std::is_move_assignable<DependentT>>::value,
int> = 0>
friend void RiegeliReset(T& dest, MakerTypeForBase&& src) {
riegeli::Reset(dest, std::move(src.maker()));
riegeli::Reset(dest, std::move(src).maker());
}

// Returns the corresponding `MakerType` which does not specify `T`.
//
// This is useful for handling `MakerType` and `MakerTypeFor` generically.
MakerType<Args...>&& maker() && { return std::move(maker_); }
MakerType<Args...>& maker() & { return maker_; }
const MakerType<Args...>& maker() const& { return maker_; }
MakerType<Args...>&& maker() && { return std::move(maker_); }
const MakerType<Args...>&& maker() const&& { return std::move(maker_); }

private:
ABSL_ATTRIBUTE_NO_UNIQUE_ADDRESS MakerType<Args...> maker_;
Expand Down

0 comments on commit 03a7e2e

Please sign in to comment.