No functional change intended. Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu. Pushed to trunk as r16-972-gafee0b19dfdc39.
gcc/cp/ChangeLog: * error.cc (cxx_format_postprocessor::clone): Update to use unique_ptr. (cxx_dump_pretty_printer::cxx_dump_pretty_printer): Likewise. (cxx_initialize_diagnostics): Likewise. gcc/ChangeLog: * pretty-print.cc (pretty_printer::pretty_printer): Use "nullptr" rather than "NULL". Remove explicit delete of m_format_postprocessor. * pretty-print.h (format_postprocessor::clone): Use unique_ptr. (pretty_printer::set_format_postprocessor): New. (pretty_printer::m_format_postprocessor): Use unique_ptr. (pp_format_postprocessor): Update for use of unique_ptr, removing reference from return type. Signed-off-by: David Malcolm <dmalc...@redhat.com> --- gcc/cp/error.cc | 10 +++++----- gcc/pretty-print.cc | 6 ++---- gcc/pretty-print.h | 17 +++++++++++------ 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/gcc/cp/error.cc b/gcc/cp/error.cc index d52dad3db293..a6a4a8c6212e 100644 --- a/gcc/cp/error.cc +++ b/gcc/cp/error.cc @@ -182,9 +182,10 @@ class cxx_format_postprocessor : public format_postprocessor : m_type_a (), m_type_b () {} - format_postprocessor *clone() const final override + std::unique_ptr<format_postprocessor> + clone() const final override { - return new cxx_format_postprocessor (); + return std::make_unique<cxx_format_postprocessor> (); } void handle (pretty_printer *pp) final override; @@ -204,8 +205,7 @@ cxx_dump_pretty_printer (int phase) if (outf) { pp_format_decoder (this) = cp_printer; - /* This gets deleted in ~pretty_printer. */ - pp_format_postprocessor (this) = new cxx_format_postprocessor (); + set_format_postprocessor (std::make_unique<cxx_format_postprocessor> ()); set_output_stream (outf); } } @@ -301,7 +301,7 @@ void cxx_initialize_diagnostics (diagnostic_context *context) { cxx_pretty_printer *pp = new cxx_pretty_printer (); - pp_format_postprocessor (pp) = new cxx_format_postprocessor (); + pp->set_format_postprocessor (std::make_unique<cxx_format_postprocessor> ()); context->set_pretty_printer (std::unique_ptr<pretty_printer> (pp)); c_common_diagnostics_set_defaults (context); diff --git a/gcc/pretty-print.cc b/gcc/pretty-print.cc index 1f38702b6117..6ecfcb26c43c 100644 --- a/gcc/pretty-print.cc +++ b/gcc/pretty-print.cc @@ -2461,7 +2461,7 @@ pretty_printer::pretty_printer (int maximum_length) m_indent_skip (0), m_wrapping (), m_format_decoder (nullptr), - m_format_postprocessor (NULL), + m_format_postprocessor (nullptr), m_token_printer (nullptr), m_emitted_prefix (false), m_need_newline (false), @@ -2487,7 +2487,7 @@ pretty_printer::pretty_printer (const pretty_printer &other) m_indent_skip (other.m_indent_skip), m_wrapping (other.m_wrapping), m_format_decoder (other.m_format_decoder), - m_format_postprocessor (NULL), + m_format_postprocessor (nullptr), m_token_printer (other.m_token_printer), m_emitted_prefix (other.m_emitted_prefix), m_need_newline (other.m_need_newline), @@ -2508,8 +2508,6 @@ pretty_printer::pretty_printer (const pretty_printer &other) pretty_printer::~pretty_printer () { - if (m_format_postprocessor) - delete m_format_postprocessor; m_buffer->~output_buffer (); XDELETE (m_buffer); free (m_prefix); diff --git a/gcc/pretty-print.h b/gcc/pretty-print.h index 066d19d4cdac..6cd9150a9d08 100644 --- a/gcc/pretty-print.h +++ b/gcc/pretty-print.h @@ -196,7 +196,7 @@ class format_postprocessor { public: virtual ~format_postprocessor () {} - virtual format_postprocessor *clone() const = 0; + virtual std::unique_ptr<format_postprocessor> clone() const = 0; virtual void handle (pretty_printer *) = 0; }; @@ -229,7 +229,7 @@ inline int & pp_indentation (pretty_printer *pp); inline bool & pp_translate_identifiers (pretty_printer *pp); inline bool & pp_show_color (pretty_printer *pp); inline printer_fn &pp_format_decoder (pretty_printer *pp); -inline format_postprocessor *& pp_format_postprocessor (pretty_printer *pp); +inline format_postprocessor *pp_format_postprocessor (pretty_printer *pp); inline bool & pp_show_highlight_colors (pretty_printer *pp); class urlifier; @@ -256,7 +256,7 @@ public: friend bool & pp_translate_identifiers (pretty_printer *pp); friend bool & pp_show_color (pretty_printer *pp); friend printer_fn &pp_format_decoder (pretty_printer *pp); - friend format_postprocessor *& pp_format_postprocessor (pretty_printer *pp); + friend format_postprocessor * pp_format_postprocessor (pretty_printer *pp); friend bool & pp_show_highlight_colors (pretty_printer *pp); friend void pp_output_formatted_text (pretty_printer *, @@ -316,6 +316,11 @@ public: void set_real_maximum_length (); int remaining_character_count_for_line (); + void set_format_postprocessor (std::unique_ptr<format_postprocessor> p) + { + m_format_postprocessor = std::move (p); + } + void dump (FILE *out, int indent) const; void DEBUG_FUNCTION dump () const { dump (stderr, 0); } @@ -356,7 +361,7 @@ private: have been processed, to allow for client-specific postprocessing. This is used by the C++ frontend for handling the %H and %I format codes (which interract with each other). */ - format_postprocessor *m_format_postprocessor; + std::unique_ptr<format_postprocessor> m_format_postprocessor; /* This is used by pp_output_formatted_text after it has converted all formatted chunks into a single list of tokens. @@ -443,10 +448,10 @@ pp_format_decoder (pretty_printer *pp) return pp->m_format_decoder; } -inline format_postprocessor *& +inline format_postprocessor * pp_format_postprocessor (pretty_printer *pp) { - return pp->m_format_postprocessor; + return pp->m_format_postprocessor.get (); } inline bool & -- 2.26.3