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

--- Comment #1 from David Malcolm <dmalcolm at gcc dot gnu.org> ---
I *think* the analyzer is correct here and is reporting a true leak.

Looking at trunk's output
   https://godbolt.org/z/czqs83v3G
I see it considering the case where an exception is thrown here:

 37 |                                    std::cout.rdbuf(nullptr);

(23) if 'std::basic_streambuf<_CharT, _Traits>* std::basic_ios<_CharT,
_Traits>::rdbuf(std::basic_streambuf<_CharT, _Traits>*) [with _CharT = char;
_Traits = std::char_traits<char>]' throws an exception...

which thus skips the call to "delete q;" at line 38.  

Should line 37 be wrapped in a try/catch?

GCC 16 emits a much more complicated path
  https://godbolt.org/z/6aerYffWE
and is likely to be buggy.

Note that:
(a) the analyzer's has had major work on exception-handling in both GCC 15 and
GCC 16 iirc
(b) I don't expect -fanalyzer to be meaningfully usable on C++ code on versions
of GCC < 17.

Reply via email to