On 10 December 2014 at 13:54, Dodji Seketeli <do...@redhat.com> wrote: >> /* Report the number of warnings and errors that occurred to the caller. */ >> >> @@ -1525,11 +1625,14 @@ gfc_diagnostics_init (void) >> { >> diagnostic_starter (global_dc) = gfc_diagnostic_starter; >> diagnostic_finalizer (global_dc) = gfc_diagnostic_finalizer; >> diagnostic_format_decoder (global_dc) = gfc_format_decoder; >> global_dc->caret_char = '^'; >> - new (&pp_warning_buffer) output_buffer (); >> + pp_warning_buffer = new output_buffer (); > > When I look at the code of the destructor the pretty_printer type > (pretty_printer::~pretty_printer) in gcc/pretty-print.c, I see that the > memory for the output buffer is de-allocated using XDELETE. So I think > the memory for the output buffer should be allocated using XNEW and the > output_buffer type should instantiated using a placement new operator > that uses that XNEWed allocated memory.
The reason we use this placement-new stuff is precisely the use of XNEW and XDELETE, since those do not call the cons/des-tructors. However, a lot of code in GCC is directly using new/delete already. I don't see any reason to not do so in the pretty-printer/diagnostics code. In fact, David Malcom recently did a similar change for tree-pretty-print.c: https://gcc.gnu.org/ml/gcc-patches/2014-11/msg03213.html But I agree that using XNEW and placement-new is probably safer for now. I'll try that and submit a new version. Cheers, Manuel.