Skip to content

Commit

Permalink
Add missing std::forward() in ExternalRef() arguments, which resu…
Browse files Browse the repository at this point in the history
…lted in

copies instead of moves.

Fix `ExternalRef` constructors so that if a type declares to supports
`ExternalRef` only by moving, then this is actually enforced.

PiperOrigin-RevId: 679116618
  • Loading branch information
QrczakMK committed Sep 26, 2024
1 parent 12ad44a commit a6c0c4b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
16 changes: 8 additions & 8 deletions riegeli/base/external_ref_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -1830,8 +1830,8 @@ class ExternalRef {
// `storage` must outlive usages of the returned `ExternalRef`.
template <
typename Arg,
std::enable_if_t<SupportsExternalRefWhole<InitializerTargetT<Arg>>::value,
int> = 0>
std::enable_if_t<
SupportsExternalRefWhole<InitializerTargetRefT<Arg>>::value, int> = 0>
explicit ExternalRef(Arg&& arg ABSL_ATTRIBUTE_LIFETIME_BOUND,
StorageWhole<Arg&&>&& storage
ABSL_ATTRIBUTE_LIFETIME_BOUND =
Expand All @@ -1846,10 +1846,10 @@ class ExternalRef {
// `substr` must be owned by the object if it gets created or moved.
//
// `storage` must outlive usages of the returned `ExternalRef`.
template <
typename Arg,
std::enable_if_t<
SupportsExternalRefSubstr<InitializerTargetT<Arg>>::value, int> = 0>
template <typename Arg,
std::enable_if_t<
SupportsExternalRefSubstr<InitializerTargetRefT<Arg>>::value,
int> = 0>
explicit ExternalRef(
Arg&& arg ABSL_ATTRIBUTE_LIFETIME_BOUND, absl::string_view substr,
StorageSubstr<Arg&&>&& storage ABSL_ATTRIBUTE_LIFETIME_BOUND =
Expand All @@ -1866,8 +1866,8 @@ class ExternalRef {
// responsible for using an appropriate type of the external object.
template <
typename Arg,
std::enable_if_t<
SupportsToStringView<const InitializerTargetT<Arg>>::value, int> = 0>
std::enable_if_t<SupportsToStringView<InitializerTargetRefT<Arg>>::value,
int> = 0>
static ExternalRef From(Arg&& arg ABSL_ATTRIBUTE_LIFETIME_BOUND,
StorageWhole<Arg&&>&& storage
ABSL_ATTRIBUTE_LIFETIME_BOUND =
Expand Down
2 changes: 1 addition & 1 deletion riegeli/bytes/backward_writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ inline bool BackwardWriter::Write(ExternalRef src) {
template <typename Src,
std::enable_if_t<SupportsExternalRefWhole<Src>::value, int>>
inline bool BackwardWriter::Write(Src&& src) {
return Write(ExternalRef(src));
return Write(ExternalRef(std::forward<Src>(src)));
}

inline bool BackwardWriter::Write(ByteFill src) {
Expand Down
2 changes: 1 addition & 1 deletion riegeli/bytes/writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -910,7 +910,7 @@ inline bool Writer::Write(ExternalRef src) {
template <typename Src,
std::enable_if_t<SupportsExternalRefWhole<Src>::value, int>>
inline bool Writer::Write(Src&& src) {
return Write(ExternalRef(src));
return Write(ExternalRef(std::forward<Src>(src)));
}

inline bool Writer::Write(ByteFill src) {
Expand Down

0 comments on commit a6c0c4b

Please sign in to comment.