--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
Passing scoped_refptr<T> by value now requires the full definition of T as the ref-count is not held inside the scoped_refptr but on T itself (in its RefCounted or RefCountedThreadSafe portion), so T needs to be defined merely to know that it implements RefCounted(ThreadSafe).
Interestingly, ref_counted_unittest.cc does verify that using an opaque type works but it requires that the template be fwd-declared as extern template class scoped_refptr<base::OpaqueRefCounted>. Such a fwd-declaration is impractical because it requires an instantiation of that extern decl in the same compilation unit (which works in isolation cases like opaque_ref_counted.(cc|h) but doesn't in headers used across compilation units..).It turns out that there are zero uses of the extern fwd-decl paradigm in our codebase outside of base/test/opaque_ref_counted.h. Furthermore, the style guide frowns upon complex fwd-decls so I guess this test is proving that a paradigm that no one uses nor should use is possible...
PS: after discussion with other people, the only potential solution we can think of would be to move the static AddRef/Release calls in ref_counted.h out of line. <hand-waving> this would prevent it from being inlined and would ensure scoped_refptr<T> only needs to be fully defined once per compilation unit -- not clear who would be in charge of defining it </hand-waving>. The performance cost of not having this inlined is likely not worth it either to save a few includes (again, the style guide frowns upon fwd-decls already).
This is how things work with std::unique_ptr: if ~unique_ptr is called (it is if you have a local unique_ptr variable, including a parameter), you need the definition of T in order to call ~T (even if the compiler can statically prove that the T* will actually be null in practice). I'd expect scoped_refptr to behave similarly.Is this a big problem in practice? I'd have expected most code which accepts an owning reference to T to already need its definition (e.g., to call its methods).
---
You received this message because you are subscribed to the Google Groups "Chromium-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev+unsubscribe@chromium.org.
On Wednesday, November 2, 2016 at 5:46:19 PM UTC+11, Dmitry Skiba wrote:If we're OK with adding one more pointer to scoped_refptr (+level of indirection), then we can hide AddRef/Release behind a function that is only touched in ctor / ptr assignment: https://codereview.chromium.org/2471043002/
Interestingly, ref_counted_unittest.cc does verify that using an opaque type works but it requires that the template be fwd-declared as extern template class scoped_refptr<base::OpaqueRefCounted>. Such a fwd-declaration is impractical because it requires an instantiation of that extern decl in the same compilation unit (which works in isolation cases like opaque_ref_counted.(cc|h) but doesn't in headers used across compilation units..).It turns out that there are zero uses of the extern fwd-decl paradigm in our codebase outside of base/test/opaque_ref_counted.h. Furthermore, the style guide frowns upon complex fwd-decls so I guess this test is proving that a paradigm that no one uses nor should use is possible...Sounds like we should remove that class/test.