Skip to content

Commit

Permalink
Fix AnyRef and AnyInitializer constructors to exclude not only exact
Browse files Browse the repository at this point in the history
conflicts with the move constructor, but also conflicts with materializing the
given object from `Initializer` etc.

This way constructing `AnyRef<Handle>` from `Initializer<AnyRef<Handle>>` is
done by materializing the `AnyRef<Handle>`, instead of wrapping a reference to
it. The latter might not work anyway because it could store a reference to an
object which is getting destroyed too soon, which is caught by
`ABSL_ATTRIBUTE_LIFETIME_BOUND`.

Cosmetics: remove old-style `absl_nullability_compatible` tag which does not
have any effect since
abseil/abseil-cpp@485f2be
and was left here by mistake.
PiperOrigin-RevId: 697950999
  • Loading branch information
QrczakMK committed Nov 19, 2024
1 parent 8119aa5 commit 6315eea
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
6 changes: 2 additions & 4 deletions riegeli/base/any.h
Original file line number Diff line number Diff line change
Expand Up @@ -392,16 +392,14 @@ class
#endif
AnyRef : public any_internal::AnyBase<Handle, 0, 0> {
public:
using absl_nullability_compatible = void;

// Creates an empty `AnyRef`.
AnyRef() noexcept { this->Initialize(); }

// Holds a `Dependency<Handle, Manager&&>`.
template <typename Manager,
std::enable_if_t<
absl::conjunction<
absl::negation<std::is_same<std::decay_t<Manager>, AnyRef>>,
absl::negation<std::is_same<TargetT<Manager>, AnyRef>>,
SupportsDependency<Handle, Manager&&>>::value,
int> = 0>
/*implicit*/ AnyRef(Manager&& manager ABSL_ATTRIBUTE_LIFETIME_BOUND);
Expand Down Expand Up @@ -719,7 +717,7 @@ template <
typename Manager,
std::enable_if_t<
absl::conjunction<
absl::negation<std::is_same<std::decay_t<Manager>, AnyRef<Handle>>>,
absl::negation<std::is_same<TargetT<Manager>, AnyRef<Handle>>>,
SupportsDependency<Handle, Manager&&>>::value,
int>>
inline AnyRef<Handle>::AnyRef(Manager&& manager ABSL_ATTRIBUTE_LIFETIME_BOUND) {
Expand Down
6 changes: 3 additions & 3 deletions riegeli/base/any_initializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ class AnyInitializer {
template <
typename Manager,
std::enable_if_t<
absl::conjunction<absl::negation<std::is_same<std::decay_t<Manager>,
AnyInitializer>>,
TargetSupportsDependency<Handle, Manager>>::value,
absl::conjunction<
absl::negation<std::is_same<TargetT<Manager>, AnyInitializer>>,
TargetSupportsDependency<Handle, Manager>>::value,
int> = 0>
/*implicit*/ AnyInitializer(Manager&& manager ABSL_ATTRIBUTE_LIFETIME_BOUND)
: construct_(ConstructMethod<Manager>),
Expand Down

0 comments on commit 6315eea

Please sign in to comment.