This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch] add -Wdelete-non-virtual-dtor


On 3 June 2011 02:55, Jason Merrill wrote:
> On 06/02/2011 06:02 PM, Jonathan Wakely wrote:
>>
>> + ? ? ? ? ? ? if (!dtor || !DECL_VINDEX (dtor))
>
> Do we really want to warn about the case where the class has no/trivial
> destructor?

I think so.  Definitely if it's an abstract class, since it's
definitely undefined behaviour.  The user might have forgotten to
define the destructor, so the warning would draw their attention to
it.

For example:

struct abc { virtual void f() = 0; };
struct interface : abc { virtual ~interface(); };
void f(abc* p) { delete p; }

The intended use might be to destroy such objects through a pointer to
interface, but f() has been defined to take the wrong type.

>> + ? ? ? ? ? ? ? ? bool abstract = false;
>> + ? ? ? ? ? ? ? ? for (x = TYPE_METHODS (type); x; x = DECL_CHAIN (x))
>> + ? ? ? ? ? ? ? ? ? if (DECL_PURE_VIRTUAL_P (x))
>> + ? ? ? ? ? ? ? ? ? ? {
>> + ? ? ? ? ? ? ? ? ? ? ? abstract = true;
>> + ? ? ? ? ? ? ? ? ? ? ? break;
>> + ? ? ? ? ? ? ? ? ? ? }
>> + ? ? ? ? ? ? ? ? if (abstract)
>
> Just check CLASSTYPE_PURE_VIRTUALS.

Thanks, I'll retest with that change ...


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]