Re: PSA: Refcounted classes should have a non-public destructor should be MOZ_FINAL where possible

2014-07-10 Thread Neil
Daniel Holbert wrote: (a) Your class should have an explicitly-declared non-public destructor. (should be 'private' or 'protected') Except for refcounted base classes (which as you note need to have a protected virtual destructor), is there a correct style as to whether the destructor

Re: PSA: Refcounted classes should have a non-public destructor should be MOZ_FINAL where possible

2014-07-10 Thread Daniel Holbert
On 07/10/2014 02:48 AM, Neil wrote: Except for refcounted base classes (which as you note need to have a protected virtual destructor), is there a correct style as to whether the destructor should be private or protected and virtual or nonvirtual? IMO, the destructor should be nonvirtual,

Re: PSA: Refcounted classes should have a non-public destructor should be MOZ_FINAL where possible

2014-07-10 Thread Benjamin Smedberg
On 7/10/2014 10:46 AM, Daniel Holbert wrote: First, if your class is abstract, then it shouldn't have AddRef/Release implementations to begin with. Those belong on the concrete subclasses -- not on your abstract base class. What's correct code for abstract class Foo (implementing

Re: PSA: Refcounted classes should have a non-public destructor should be MOZ_FINAL where possible

2014-07-10 Thread Daniel Holbert
On 07/10/2014 08:03 AM, Benjamin Smedberg wrote: On 7/10/2014 10:46 AM, Daniel Holbert wrote: Shouldn't the refcounting still be on the concrete classes? Why? This happens for example with nsRunnable: nsRunnable does the refcounting, and all the derivations of nsRunnable only have to worry

Re: PSA: Refcounted classes should have a non-public destructor should be MOZ_FINAL where possible

2014-06-20 Thread Benoit Jacob
Here's an update on this front. In Bug 1027251 https://bugzilla.mozilla.org/show_bug.cgi?id=1027251 we added a static_assert as discussed in this thread, which discovered all remaining instances, and we fixed the easy ones, which were the majority. The harder ones have been temporarily

Re: PSA: Refcounted classes should have a non-public destructor should be MOZ_FINAL where possible

2014-05-30 Thread Aryeh Gregor
On Thu, May 29, 2014 at 12:27 AM, Daniel Holbert dholb...@mozilla.com wrote: For now, our code isn't clean enough for this sort of static_assert to be doable. :-/ And we have at least one instance of a refcounted class that's semi-intentionally (albeit carefully) declared on the stack:

PSA: Refcounted classes should have a non-public destructor should be MOZ_FINAL where possible

2014-05-28 Thread Daniel Holbert
Hi dev-platform, PSA: if you are adding a concrete class with AddRef/Release implementations (e.g. via NS_INLINE_DECL_REFCOUNTING), please be aware of the following best-practices: (a) Your class should have an explicitly-declared non-public destructor. (should be 'private' or 'protected')

Re: PSA: Refcounted classes should have a non-public destructor should be MOZ_FINAL where possible

2014-05-28 Thread Benoit Jacob
Awesome work! By the way, I just figured a way that you could static_assert so that at least on supporting C++11 compilers, we would automatically catch this. The basic C++11 tool here is std::is_destructible from type_traits, but it has a problem: it only returns false if the destructor is

Re: PSA: Refcounted classes should have a non-public destructor should be MOZ_FINAL where possible

2014-05-28 Thread Benoit Jacob
Actually that test program contradicts what I said --- my IsDestructorPrivateOrDeleted produces exactly the same result as !is_destructible, and is_destructible does return 0 for the class with private destructor. So you could just use that! Benoit 2014-05-28 16:51 GMT-04:00 Benoit Jacob

Re: PSA: Refcounted classes should have a non-public destructor should be MOZ_FINAL where possible

2014-05-28 Thread Daniel Holbert
Nice! So it sounds like we could use std::is_destructible to harden our refcounting-impl macros (like NS_INLINE_DECL_REFCOUNTING), by having those macros include a static_assert which enforces that they're only invoked by classes with private/protected destructors. (I'll bet that this