News for hackers. Stuff that matters.
Re:When noexcept? by cmrdporcupine on Thursday December 15, 2016 @11:22AM (#13185674)
Cautioun.

And the destructor has to check for initialization before cleanup.

Re:When noexcept? by ryandrake on Thursday December 15, 2016 @02:48PM (#13187606)
Am I the only one that finds it ironic that you have a typo in the word "Caution"?

I'd be very suspicious of any failure avoidance system that relies on "user caution".

Re:When noexcept? by AnimalMuppet on Thursday December 15, 2016 @04:50PM (#13188791)
But all failure avoidance systems rely on user caution. Error return values have to be checked. Exceptions have to be caught and handled (correctly). RAII has to be done everywhere a resource is allocated.

Now, true, some of these impose lesser burdens than others. Arguably, RAII imposes the least - but not zero. And if you forget with any resource, for that resource you are vulnerable.

Re:When noexcept? by lmm on Friday December 16, 2016 @04:37AM (#13192139)
That we can't make things perfect is no reason not to make things better.

And ultimately it should be possible to enforce that all resources are managed, because ultimately all resource interfaces have to be provided by the language runtime. To a certain extent enforcing user-defined invariants is always a matter of taste, but at the same time a language that makes it easy makes people a lot better at it.

Re:When noexcept? by SamReidHughes on Thursday December 15, 2016 @03:33PM (#13188083)
You'll get a run time error.
Re:When noexcept? by lmm on Friday December 16, 2016 @11:50AM (#13194576)
Maybe. Or maybe you'll get an invisible resource leak, or silent data corruption, or an RCE vulnerability.
Re:When noexcept? by SamReidHughes on Friday December 16, 2016 @04:52PM (#13197219)
Well I don't know about that. If you have a datatype whose constructors can't throw, it should still assert at run time about its state that it's been initialized. Like, you have to actually do that, of course. So there's more surface area for mistakes inside the object, but from the outside of the object, which is what I think this sub-thread is talking about, they get caught at run time.
Re:When noexcept? by lmm on Monday December 19, 2016 @09:24AM (#13211536)
It shouldn't have to be assertions though - you should make it correct by, well, construction. When the fields are RAII the constructor can just initialize them. If your class has different possible states and flags it's usually correct to promote the different states to differnt types (subclasses).
Re:When noexcept? by SamReidHughes on Monday December 19, 2016 @08:16PM (#13216525)
I don't think we're disagreeing about anything. The scope of my comment is in reference to "So how do you protect yourself against inadvertently passing around uninitialized objects?" The answer is, with a run-time error.