Local static smart pointers
Categories
(Core :: XPCOM, task, P1)
Tracking
()
Tracking | Status | |
---|---|---|
firefox70 | --- | fixed |
People
(Reporter: bugzilla, Assigned: bugzilla)
References
Details
Attachments
(1 file)
As discussed with Nathan last week on IRC, I'd like to write a smart pointer that can be used for C++11 "magic statics", such that we can initialize them like so:
void foo() {
static StaticLocalAutoPtr<Bar> sInstance = []() -> Bar* {
// Create an instance of Bar
}();
// ...
}
In bug 1569681 I added a new MOZ_STATIC_LOCAL_CLASS
annotation for static analysis that forces a class to have a trivial destructor and only be instantiated as a static local, so we can now implement this without fear of being used incorrectly.
Assignee | ||
Comment 1•5 years ago
|
||
This patch adds smart pointers to be used for initializing objects as C++11
"magic statics", ie. as static local variables that are initialized in a
thread-safe manner.
Unlike Static{Auto,Ref}Ptr, they may have non-trivial constructors, though they
must still have trivial destructors to prevent emission of atexit calls.
The new classes use the new MOZ_STATIC_LOCAL_CLASS
annotation which ensures
their instantiations are static locals and prevents non-trivial destructors.
Pushed by aklotz@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/0356a4d2ee45 Add StaticLocalAutoPtr and StaticLocalRefPtr to XPCOM; r=froydnj
Comment 3•5 years ago
|
||
bugherder |
Description
•