[cfe-dev] Dynamic memory allocation and deleted definitions

Halfdan Ingvarsson halfdan at sidefx.com
Wed Nov 13 12:58:19 PST 2013


On 13-11-13 03:22 PM, Rahul Jain wrote:
> But assume if the constructor is not throwing, and all the objects of 
> the array get constructed completely, than where does the need of the 
> destructor call arise from?
The compiler can't fully reason about that if the constructor is 
non-trivial. What if the constructor calls a function in a different 
compilation unit that throws an exception? Member variable constructors 
throwing? Etc.

The throw() function decorator is not enough. In fact you should never 
use it. It's also a pessimisation.

> Also what exactly is the difference in this context when we define a 
> default constructor in our class vs a synthesized default constructor 
> in our class?
It's not quite as clear cut as just a difference between user-defined 
and synthesized. There are subtleties at play. See: 
http://stackoverflow.com/a/3899237/2533196

> g++ seems to accept the synthesized version whereas errors when one 
> defines a default constructor(as Halfsan mentioned above), whereas 
> clang rejects both the versions. Who is at fault here?
clang is being conservative, which is usually a Good Thing(tm). In this 
case, with a trivial default constructor, then clang should probably not 
be emitting an error. However, that's just my opinion and I'm sure there 
could be a good reason, that I'm not currently aware of, why it should 
still error out for all cases. I'll let the real experts decide on that 
though.

  - ½




More information about the cfe-dev mailing list