5 #ifndef INCLUDE_CPPGC_PREFINALIZER_H_
6 #define INCLUDE_CPPGC_PREFINALIZER_H_
8 #include "cppgc/internal/compiler-specific.h"
9 #include "cppgc/internal/prefinalizer-handler.h"
10 #include "cppgc/liveness-broker.h"
17 class PrefinalizerRegistration final {
20 static_assert(
sizeof(&T::InvokePreFinalizer) > 0,
21 "USING_PRE_FINALIZER(T) must be defined.");
24 {self, T::InvokePreFinalizer}
);
27 void*
operator new(size_t,
void* location) =
delete;
33 #define CPPGC_USING_PRE_FINALIZER(Class, PreFinalizer)
35 static bool InvokePreFinalizer(const cppgc::LivenessBroker& liveness_broker,
37 static_assert(cppgc::IsGarbageCollectedOrMixinTypeV<Class>,
38 "Only garbage collected objects can have prefinalizers");
39 Class* self = static_cast<Class*>(object);
40 if (liveness_broker.IsHeapObjectAlive(self)) return false;
41 self->Class::PreFinalizer();
47 prefinalizer_dummy_{this};
48 static_assert(true, "Force semicolon.")