[Bug c++/33715] Suggest -Wmemleak warning for C++

redi at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Thu Mar 28 12:47:00 GMT 2019


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=33715

--- Comment #6 from Jonathan Wakely <redi at gcc dot gnu.org> ---
But a warning that says "this resource might be leaked, you should add
try-catch to clean it up" would be suggesting awful code that goes against all
good design guidance.

A more useful warning would be to warn "about local variables assigned via
operator new or operator new[]" period. Forget the "but then are not freed in
an exception handling clause in case of an exception" part completely.

We should not be adding warnings to say "fix this fragile, manual memory
mangement code by adding fragile, manual error handling code".

https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#r11-avoid-calling-new-and-delete-explicitly
https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#r12-immediately-give-the-result-of-an-explicit-resource-allocation-to-a-manager-object
https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#r20-use-unique_ptr-or-shared_ptr-to-represent-ownership


More information about the Gcc-bugs mailing list