TestKnownLive.cpp (732B)
1 #include <mozilla/RefPtr.h> 2 3 #define MOZ_KNOWN_LIVE __attribute__((annotate("moz_known_live"))) 4 5 class Foo { 6 // dummy refcounting 7 public: 8 uint32_t AddRef() { return 0; } 9 uint32_t Release() { return 0; } 10 11 private: 12 ~Foo() = default; 13 }; 14 15 class Bar { 16 MOZ_KNOWN_LIVE RefPtr<Foo> mFoo; 17 Bar() : mFoo(new Foo()) {} 18 ~Bar() { mFoo = nullptr; } 19 20 void Baz() { 21 mFoo = nullptr; // expected-error {{MOZ_KNOWN_LIVE members can only be modified by constructors and destructors}} 22 } 23 }; 24 25 class Bar2 { 26 MOZ_KNOWN_LIVE Foo *mFoo; 27 Bar2() : mFoo(new Foo()) {} 28 ~Bar2() { mFoo = nullptr; } 29 30 void Baz() { 31 mFoo = nullptr; // expected-error {{MOZ_KNOWN_LIVE members can only be modified by constructors and destructors}} 32 } 33 };