Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu.
Pushed to trunk as r16-253-g9c4336cbf05228.

gcc/c-family/ChangeLog:
        * name-hint.h (name_hint::name_hint): Use std::unique_ptr for
        param.

gcc/c/ChangeLog:
        * c-decl.cc: Include "make-unique.h".
        (lookup_name_fuzzy): Use ::make_unique rather than "new" when
        making suggest_missing_header and suggest_missing_option.
        * c-parser.cc: Include "make-unique.h"
        (c_parser_error_richloc): Use ::make_unique rather than "new" when
        making suggest_missing_header.

gcc/cp/ChangeLog:
        * name-lookup.cc: Include "make-unique.h".
        (namespace_hints::convert_candidates_to_name_hint): Use
        ::make_unique rather than "new" when making
        show_candidate_location and suggest_alternatives.
        (namespace_hints::maybe_decorate_with_limit): Likewise when making
        namespace_limit_reached.
        (suggest_alternatives_for_1): Likewise when making
        suggest_missing_option.
        (maybe_suggest_missing_std_header): Likewise when making
        missing_std_header.
        (macro_use_before_def::maybe_make): Use std::unique_ptr.
        (macro_use_before_def::macro_use_before_def): Make public.
        (lookup_name_fuzzy): Use ::make_unique rather than "new" when
        making suggest_missing_header.
        * parser.cc: Include "make-unique.h".
        (cp_parser_error_1): Use ::make_unique rather than "new" when
        making suggest_missing_header.

Signed-off-by: David Malcolm <dmalc...@redhat.com>
---
 gcc/c-family/name-hint.h |  6 +++--
 gcc/c/c-decl.cc          | 19 +++++++++-------
 gcc/c/c-parser.cc        |  8 ++++---
 gcc/cp/name-lookup.cc    | 49 +++++++++++++++++++++++-----------------
 gcc/cp/parser.cc         |  9 +++++---
 5 files changed, 54 insertions(+), 37 deletions(-)

diff --git a/gcc/c-family/name-hint.h b/gcc/c-family/name-hint.h
index 3d4f2f5e205..13ade7123f8 100644
--- a/gcc/c-family/name-hint.h
+++ b/gcc/c-family/name-hint.h
@@ -85,8 +85,10 @@ class name_hint
 public:
   name_hint () : m_suggestion (NULL), m_deferred () {}
 
-  name_hint (const char *suggestion, deferred_diagnostic *deferred)
-  : m_suggestion (suggestion), m_deferred (deferred)
+  name_hint (const char *suggestion,
+            std::unique_ptr<deferred_diagnostic> deferred)
+  : m_suggestion (suggestion),
+    m_deferred (std::move (deferred))
   {
   }
 
diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc
index e7aee8a0f4b..e7765f6d951 100644
--- a/gcc/c/c-decl.cc
+++ b/gcc/c/c-decl.cc
@@ -62,6 +62,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "omp-offload.h"  /* For offload_vars.  */
 #include "c-parser.h"
 #include "gcc-urlifier.h"
+#include "make-unique.h"
 
 #include "tree-pretty-print.h"
 
@@ -4547,10 +4548,11 @@ lookup_name_fuzzy (tree name, enum 
lookup_name_fuzzy_kind kind, location_t loc)
     = get_c_stdlib_header_for_name (IDENTIFIER_POINTER (name));
 
   if (header_hint)
-    return name_hint (NULL,
-                     new suggest_missing_header (loc,
-                                                 IDENTIFIER_POINTER (name),
-                                                 header_hint));
+    return name_hint
+      (nullptr,
+       ::make_unique<suggest_missing_header> (loc,
+                                             IDENTIFIER_POINTER (name),
+                                             header_hint));
 
   /* Next, look for exact matches for builtin defines that would have been
      defined if the user had passed a command-line option (e.g. -fopenmp
@@ -4558,10 +4560,11 @@ lookup_name_fuzzy (tree name, enum 
lookup_name_fuzzy_kind kind, location_t loc)
   diagnostic_option_id option_id
     = get_option_for_builtin_define (IDENTIFIER_POINTER (name));
   if (option_id.m_idx > 0)
-    return name_hint (nullptr,
-                     new suggest_missing_option (loc,
-                                                 IDENTIFIER_POINTER (name),
-                                                 option_id));
+    return name_hint
+      (nullptr,
+       ::make_unique<suggest_missing_option> (loc,
+                                             IDENTIFIER_POINTER (name),
+                                             option_id));
 
   /* Only suggest names reserved for the implementation if NAME begins
      with an underscore.  */
diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc
index 22ec0f849b7..2e7ba28f404 100644
--- a/gcc/c/c-parser.cc
+++ b/gcc/c/c-parser.cc
@@ -77,6 +77,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "asan.h"
 #include "c-family/c-ubsan.h"
 #include "gcc-urlifier.h"
+#include "make-unique.h"
 
 /* We need to walk over decls with incomplete struct/union/enum types
    after parsing the whole translation unit.
@@ -1072,9 +1073,10 @@ c_parser_error_richloc (c_parser *parser, const char 
*gmsgid,
       const char *header_hint
        = get_c_stdlib_header_for_string_macro_name (token_name);
       if (header_hint != NULL)
-       h = name_hint (NULL, new suggest_missing_header (token->location,
-                                                        token_name,
-                                                        header_hint));
+       h = name_hint (nullptr,
+                      ::make_unique<suggest_missing_header> (token->location,
+                                                             token_name,
+                                                             header_hint));
     }
 
   c_parse_error (gmsgid,
diff --git a/gcc/cp/name-lookup.cc b/gcc/cp/name-lookup.cc
index aa2dc0e47d3..27b32f08dc3 100644
--- a/gcc/cp/name-lookup.cc
+++ b/gcc/cp/name-lookup.cc
@@ -35,6 +35,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "c-family/known-headers.h"
 #include "c-family/c-spellcheck.h"
 #include "bitmap.h"
+#include "make-unique.h"
 
 static cxx_binding *cxx_binding_make (tree value, tree type);
 static cp_binding_level *innermost_nonclass_level (void);
@@ -7085,13 +7086,16 @@ namespace_hints::convert_candidates_to_name_hint ()
       /* Clean up CANDIDATES.  */
       m_candidates.release ();
       return name_hint (expr_to_string (candidate),
-                       new show_candidate_location (m_loc, candidate));
+                       ::make_unique<show_candidate_location> (m_loc,
+                                                               candidate));
     }
   else if (m_candidates.length () > 1)
     /* If we have more than one candidate, issue a name_hint without a single
        "suggestion", but with a deferred diagnostic that lists the
        various candidates.  This takes ownership of m_candidates.  */
-    return name_hint (NULL, new suggest_alternatives (m_loc, m_candidates));
+    return name_hint (NULL,
+                     ::make_unique<suggest_alternatives> (m_loc,
+                                                          m_candidates));
 
   /* Otherwise, m_candidates ought to be empty, so no cleanup is necessary.  */
   gcc_assert (m_candidates.length () == 0);
@@ -7111,10 +7115,11 @@ name_hint
 namespace_hints::maybe_decorate_with_limit (name_hint hint)
 {
   if (m_limited)
-    return name_hint (hint.suggestion (),
-                     new namespace_limit_reached (m_loc, m_limit,
-                                                  m_name,
-                                                  hint.take_deferred ()));
+    return name_hint
+      (hint.suggestion (),
+       ::make_unique<namespace_limit_reached> (m_loc, m_limit,
+                                              m_name,
+                                              hint.take_deferred ()));
   else
     return hint;
 }
@@ -7191,10 +7196,11 @@ suggest_alternatives_for_1 (location_t location, tree 
name,
   diagnostic_option_id option_id
     = get_option_for_builtin_define (IDENTIFIER_POINTER (name));
   if (option_id.m_idx > 0)
-    return name_hint (nullptr,
-                     new suggest_missing_option (location,
-                                                 IDENTIFIER_POINTER (name),
-                                                 option_id));
+    return name_hint
+      (nullptr,
+       ::make_unique<suggest_missing_option> (location,
+                                             IDENTIFIER_POINTER (name),
+                                             option_id));
 
   /* Otherwise, consider misspellings.  */
   if (!suggest_misspellings)
@@ -7322,8 +7328,9 @@ maybe_suggest_missing_std_header (location_t location, 
tree name)
   if (!header_hint)
     return name_hint ();
 
-  return name_hint (NULL, new missing_std_header (location, name_str,
-                                                 header_hint));
+  return name_hint (nullptr,
+                   ::make_unique<missing_std_header> (location, name_str,
+                                                      header_hint));
 }
 
 /* Attempt to generate a name_hint that suggests a missing header file
@@ -7705,12 +7712,12 @@ class macro_use_before_def : public deferred_diagnostic
  public:
   /* Factory function.  Return a new macro_use_before_def instance if
      appropriate, or return NULL. */
-  static macro_use_before_def *
+  static std::unique_ptr<macro_use_before_def>
   maybe_make (location_t use_loc, cpp_hashnode *macro)
   {
     location_t def_loc = cpp_macro_definition_location (macro);
     if (def_loc == UNKNOWN_LOCATION)
-      return NULL;
+      return nullptr;
 
     /* We only want to issue a note if the macro was used *before* it was
        defined.
@@ -7718,12 +7725,11 @@ class macro_use_before_def : public deferred_diagnostic
        used, leaving it unexpanded (e.g. by using the wrong argument
        count).  */
     if (!linemap_location_before_p (line_table, use_loc, def_loc))
-      return NULL;
+      return nullptr;
 
-    return new macro_use_before_def (use_loc, macro);
+    return ::make_unique<macro_use_before_def> (use_loc, macro);
   }
 
- private:
   /* Ctor.  LOC is the location of the usage.  MACRO is the
      macro that was used.  */
   macro_use_before_def (location_t loc, cpp_hashnode *macro)
@@ -7790,10 +7796,11 @@ lookup_name_fuzzy (tree name, enum 
lookup_name_fuzzy_kind kind, location_t loc)
   const char *header_hint
     = get_cp_stdlib_header_for_name (IDENTIFIER_POINTER (name));
   if (header_hint)
-    return name_hint (NULL,
-                     new suggest_missing_header (loc,
-                                                 IDENTIFIER_POINTER (name),
-                                                 header_hint));
+    return name_hint
+      (nullptr,
+       ::make_unique<suggest_missing_header> (loc,
+                                             IDENTIFIER_POINTER (name),
+                                             header_hint));
 
   best_match <tree, const char *> bm (name);
 
diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index 3628cfefa07..6cdf262af1a 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -50,6 +50,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "contracts.h"
 #include "bitmap.h"
 #include "builtins.h"
+#include "make-unique.h"
 
 
 /* The lexer.  */
@@ -3434,9 +3435,11 @@ cp_parser_error_1 (cp_parser* parser, const char* gmsgid,
          const char *header_hint
            = get_cp_stdlib_header_for_string_macro_name (token_name);
          if (header_hint != NULL)
-           h = name_hint (NULL, new suggest_missing_header (token->location,
-                                                            token_name,
-                                                            header_hint));
+           h = name_hint
+             (nullptr,
+              ::make_unique<suggest_missing_header> (token->location,
+                                                     token_name,
+                                                     header_hint));
        }
 
   /* Actually emit the error.  */
-- 
2.26.3

Reply via email to