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: [RFA][PATCH] Provide a class interface into substitute_and_fold.


On 10/30/2017 03:32 AM, Pedro Alves wrote:
> On 10/25/2017 06:20 PM, Jeff Law wrote:
> 
>> My conclusion on the virtual dtor issue is that it's not strictly needed
>> right  now.
>>
>> IIUC the issue is you could do something like
>>
>> base *foo = new derived ();
>> [ ... ]
>> delete foo;
>>
>> If the base's destructor is not virtual and foo is a base * pointing to
>> a derived object then the deletion invokes undefined behavior.
>>
>> In theory we shouldn't be doing such things :-)  In fact, if there's a
>> way to prevent this with some magic on the base class I'd love to know
>> about it.
> 
> There is: make the base class destructor protected.
I was just reviewing our coding conventions, mostly because I thought we
had something about using protected.  While doing so I see that our
conventions explicitly indicate that a polymorphic class should have a
virtual destructor.

So even though there's another solution and I don't think these objects
are likely to suffer from the problems noted above, I'm just going to
change things to follow our existing conventions -- just because I'm not
dynamically allocating these objects doesn't mean someone else won't later..


Jeff


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