Re:A bug in GCC that may cause memory leaks in valid C++ pro...
by faragon on Friday April 28, 2017 @07:05AM
(#14218418)
C++ exceptions are dangerous, even when working as expected. In my opinion, C++ without exceptions (or the minimal for e.g. logging the error -division by 0, invalid memory access, etc.-) is a fine language.
[ Parent
| on HN ]
Re:A bug in GCC that may cause memory leaks in valid C++ pro...
by lmm on Friday April 28, 2017 @07:48AM
(#14218634)
Without exceptions you can't do RAII (because you can't do nontrivial work in constructors, because you have no way to report failure) which is probably C++'s one real selling point. (There are other reasons I'd say it isn't a fine language - mainly the lack of sum types and the way templates are only checked after full expansion (that one will at least be fixed if and when concepts make it into the language)).
Re:A bug in GCC that may cause memory leaks in valid C++ pro...
by nathell on Friday April 28, 2017 @07:59AM
(#14218686)
RAII used to be incompatible with exceptions (I'm not sure whether anything changed for the better in C++17). The reason is that you can't throw exceptions from destructors, and e.g., on Linux, destruction of the file object (wrapping a file descriptor) can result in an error because close() may well return -1 setting errno to EIO. See `man 2 close` for details.
Re:A bug in GCC that may cause memory leaks in valid C++ pro...
by tcbawo on Friday April 28, 2017 @08:25AM
(#14218813)
That's really not true. It takes a little discipline to ensure your constructor will succeed prior to calling it, but it's worth it. You generally want to make your destructor noexcept, so you get free implicit move optimizations.