Re:A bug in GCC that may cause memory leaks in valid C++ pro...
by mnarayan01 on Thursday April 27, 2017 @09:37PM
(#14216291)
I'm more talking about the exception behavior looking at e.g. https://wandbox.org/permlink/S5paK3Z9NpeCv3I0 (which exhibits the same bug). I mean you're right, and the fact that the User object is temporary should presumably not keep the first Resource destructor from firing, just it seems weird. I guess in my defense, apparently it seems weird to GCC as well.
Re:A bug in GCC that may cause memory leaks in valid C++ pro...
by JonathonW on Friday April 28, 2017 @12:47AM
(#14216919)
The spec also explicitly addresses that (automatic objects' destructors must be called after an exception)-- see section 15.2 in the C++14 spec.
There is no ambiguity in the spec here; this is a GCC bug.
Re:A bug in GCC that may cause memory leaks in valid C++ pro...
by maxlybbert on Thursday April 27, 2017 @05:34PM
(#14214909)
I don't have the specs either, but I do remember that in Design and Evolution of C++, Stroustrup discusses nailing down the lifetime of temporary objects. I believe it was in the first standard (i.e. 1998).
I'm presuming it's the same in earlier versions of the language, but I don't have those specs handy ATM.