tools/gn: Change auto to not deduce raw pointers.

This patch updates the code to prevent auto deducing to a raw pointer.

R=brettw@chromium.org, danakj, dcheng
BUG=554600

Review-Url: https://codereview.chromium.org/2105553005
Cr-Original-Commit-Position: refs/heads/master@{#405292}
Cr-Mirrored-From: https://chromium.googlesource.com/chromium/src
Cr-Mirrored-Commit: 238f0a029f813ddc3c5a3438d8896a01cf1c5aaf
diff --git a/tools/gn/builder.cc b/tools/gn/builder.cc
index 036d390..93aec15 100644
--- a/tools/gn/builder.cc
+++ b/tools/gn/builder.cc
@@ -33,7 +33,7 @@
 bool RecursiveFindCycle(const BuilderRecord* search_in,
                         std::vector<const BuilderRecord*>* path) {
   path->push_back(search_in);
-  for (const auto& cur : search_in->unresolved_deps()) {
+  for (auto* cur : search_in->unresolved_deps()) {
     std::vector<const BuilderRecord*>::iterator found =
         std::find(path->begin(), path->end(), cur);
     if (found != path->end()) {
@@ -182,7 +182,7 @@
       bad_records.push_back(src);
 
       // Check dependencies.
-      for (const auto& dest : src->unresolved_deps()) {
+      for (auto* dest : src->unresolved_deps()) {
         if (!dest->item()) {
           depstring += src->label().GetUserVisibleName(true) +
               "\n  needs " + dest->label().GetUserVisibleName(true) + "\n";
@@ -204,7 +204,7 @@
       // Something's very wrong, just dump out the bad nodes.
       depstring = "I have no idea what went wrong, but these are unresolved, "
           "possibly due to an\ninternal error:";
-      for (const auto& bad_record : bad_records) {
+      for (auto* bad_record : bad_records) {
         depstring += "\n\"" +
             bad_record->label().GetUserVisibleName(false) + "\"";
       }
@@ -252,7 +252,7 @@
   // anything they depend on is actually written, the "generate" flag isn't
   // relevant and means extra book keeping. Just force load any deps of this
   // config.
-  for (const auto& cur : record->all_deps())
+  for (auto* cur : record->all_deps())
     ScheduleItemLoadIfNecessary(cur);
 
   return true;
@@ -408,7 +408,7 @@
     return;  // Already set.
   record->set_should_generate(true);
 
-  for (const auto& cur : record->all_deps()) {
+  for (auto* cur : record->all_deps()) {
     if (!cur->should_generate()) {
       ScheduleItemLoadIfNecessary(cur);
       RecursiveSetShouldGenerate(cur, false);
diff --git a/tools/gn/command_ls.cc b/tools/gn/command_ls.cc
index c9b9672..f53a727 100644
--- a/tools/gn/command_ls.cc
+++ b/tools/gn/command_ls.cc
@@ -100,7 +100,7 @@
     matches = setup->builder()->GetAllResolvedTargets();
   } else {
     // List all resolved targets in the default toolchain.
-    for (const auto& target : setup->builder()->GetAllResolvedTargets()) {
+    for (auto* target : setup->builder()->GetAllResolvedTargets()) {
       if (target->settings()->is_default())
         matches.push_back(target);
     }
diff --git a/tools/gn/command_refs.cc b/tools/gn/command_refs.cc
index 413a98f..014d7e8 100644
--- a/tools/gn/command_refs.cc
+++ b/tools/gn/command_refs.cc
@@ -32,7 +32,7 @@
 
 // Populates the reverse dependency map for the targets in the Setup.
 void FillDepMap(Setup* setup, DepMap* dep_map) {
-  for (const auto& target : setup->builder()->GetAllResolvedTargets()) {
+  for (auto* target : setup->builder()->GetAllResolvedTargets()) {
     for (const auto& dep_pair : target->GetDeps(Target::DEPS_ALL))
       dep_map->insert(std::make_pair(dep_pair.ptr, target));
   }
@@ -160,7 +160,7 @@
                               bool all_toolchains,
                               UniqueVector<const Target*>* matches) {
   Label default_toolchain = setup->loader()->default_toolchain_label();
-  for (const auto& target : all_targets) {
+  for (auto* target : all_targets) {
     if (!all_toolchains) {
       // Only check targets in the default toolchain.
       if (target->label().GetToolchainLabel() != default_toolchain)
@@ -189,7 +189,7 @@
                                  bool all_toolchains,
                                  UniqueVector<const Target*>* matches) {
   Label default_toolchain = setup->loader()->default_toolchain_label();
-  for (const auto& target : all_targets) {
+  for (auto* target : all_targets) {
     if (!all_toolchains) {
       // Only check targets in the default toolchain.
       if (target->label().GetToolchainLabel() != default_toolchain)
@@ -442,7 +442,7 @@
     GetTargetsContainingFile(setup, all_targets, file, all_toolchains,
                              &explicit_target_matches);
   }
-  for (const auto& config : config_matches) {
+  for (auto* config : config_matches) {
     GetTargetsReferencingConfig(setup, all_targets, config, all_toolchains,
                                 &explicit_target_matches);
   }
diff --git a/tools/gn/commands.cc b/tools/gn/commands.cc
index 8682d92..a646679 100644
--- a/tools/gn/commands.cc
+++ b/tools/gn/commands.cc
@@ -298,7 +298,7 @@
                           const std::vector<const Target*>& targets) {
   // Putting the labels into a set automatically sorts them for us.
   std::set<Label> unique_labels;
-  for (const auto& target : targets)
+  for (auto* target : targets)
     unique_labels.insert(target->label());
 
   // Grab the label of the default toolchain from the first target.
@@ -446,7 +446,7 @@
 void FilterTargetsByPatterns(const std::vector<const Target*>& input,
                              const std::vector<LabelPattern>& filter,
                              std::vector<const Target*>* output) {
-  for (const auto& target : input) {
+  for (auto* target : input) {
     for (const auto& pattern : filter) {
       if (pattern.Matches(target->label())) {
         output->push_back(target);
@@ -459,7 +459,7 @@
 void FilterTargetsByPatterns(const std::vector<const Target*>& input,
                              const std::vector<LabelPattern>& filter,
                              UniqueVector<const Target*>* output) {
-  for (const auto& target : input) {
+  for (auto* target : input) {
     for (const auto& pattern : filter) {
       if (pattern.Matches(target->label())) {
         output->push_back(target);
diff --git a/tools/gn/function_get_target_outputs.cc b/tools/gn/function_get_target_outputs.cc
index 6e3cf65..4e1baf8 100644
--- a/tools/gn/function_get_target_outputs.cc
+++ b/tools/gn/function_get_target_outputs.cc
@@ -92,7 +92,7 @@
     *err = Err(function, "No targets defined in this context.");
     return Value();
   }
-  for (const auto& item : *collector) {
+  for (auto* item : *collector) {
     if (item->label() != label)
       continue;
 
diff --git a/tools/gn/header_checker.cc b/tools/gn/header_checker.cc
index 1002081..5b15643 100644
--- a/tools/gn/header_checker.cc
+++ b/tools/gn/header_checker.cc
@@ -129,7 +129,7 @@
                              const std::vector<const Target*>& targets)
     : main_loop_(base::MessageLoop::current()),
       build_settings_(build_settings) {
-  for (const auto& target : targets)
+  for (auto* target : targets)
     AddTargetToFileMap(target, &file_map_);
 }
 
@@ -140,7 +140,7 @@
                         bool force_check,
                         std::vector<Err>* errors) {
   FileMap files_to_check;
-  for (const auto& check : to_check)
+  for (auto* check : to_check)
     AddTargetToFileMap(check, &files_to_check);
   RunCheckOverFiles(files_to_check, force_check);
 
@@ -567,9 +567,9 @@
   std::string msg = "It is not in any dependency of\n  " +
       from_target->label().GetUserVisibleName(include_toolchain);
   msg += "\nThe include file is in the target(s):\n";
-  for (const auto& target : targets_with_matching_toolchains)
+  for (auto* target : targets_with_matching_toolchains)
     msg += "  " + target->label().GetUserVisibleName(include_toolchain) + "\n";
-  for (const auto& target : targets_with_other_toolchains)
+  for (auto* target : targets_with_other_toolchains)
     msg += "  " + target->label().GetUserVisibleName(include_toolchain) + "\n";
   if (targets_with_other_toolchains.size() +
       targets_with_matching_toolchains.size() > 1)
diff --git a/tools/gn/input_conversion_unittest.cc b/tools/gn/input_conversion_unittest.cc
index 2c4afea..c5209b0 100644
--- a/tools/gn/input_conversion_unittest.cc
+++ b/tools/gn/input_conversion_unittest.cc
@@ -158,7 +158,7 @@
       "[rebase_path(\"//\")]",
   };
 
-  for (auto test : kTests) {
+  for (auto* test : kTests) {
     Err err;
     std::string input(test);
     Value result = ConvertInputToValue(settings(), input, nullptr,
diff --git a/tools/gn/loader.cc b/tools/gn/loader.cc
index 69fb766..1899df7 100644
--- a/tools/gn/loader.cc
+++ b/tools/gn/loader.cc
@@ -273,7 +273,7 @@
 
 
   // Pass all of the items that were defined off to the builder.
-  for (auto& item : collected_items) {
+  for (auto*& item : collected_items) {
     settings->build_settings()->ItemDefined(base::WrapUnique(item));
     item = nullptr;
   }
diff --git a/tools/gn/ninja_binary_target_writer.cc b/tools/gn/ninja_binary_target_writer.cc
index 9b0458a..129ddb1 100644
--- a/tools/gn/ninja_binary_target_writer.cc
+++ b/tools/gn/ninja_binary_target_writer.cc
@@ -948,7 +948,7 @@
   DCHECK(extra_object_files.empty());
 
   std::vector<OutputFile> order_only_deps;
-  for (const auto& dep : non_linkable_deps)
+  for (auto* dep : non_linkable_deps)
     order_only_deps.push_back(dep->dependency_output_file());
 
   WriteStampForTarget(object_files, order_only_deps);
@@ -965,8 +965,7 @@
   }
 
   // Inherited libraries.
-  for (const auto& inherited_target :
-           target_->inherited_libraries().GetOrdered()) {
+  for (auto* inherited_target : target_->inherited_libraries().GetOrdered()) {
     ClassifyDependency(inherited_target, extra_object_files,
                        linkable_deps, non_linkable_deps);
   }
@@ -1029,7 +1028,7 @@
     out_ << " ||";
 
     // Non-linkable targets.
-    for (const auto& non_linkable_dep : non_linkable_deps) {
+    for (auto* non_linkable_dep : non_linkable_deps) {
       out_ << " ";
       path_output_.WriteFile(out_, non_linkable_dep->dependency_output_file());
     }
diff --git a/tools/gn/ninja_build_writer.cc b/tools/gn/ninja_build_writer.cc
index 627edb2..8ee90b0 100644
--- a/tools/gn/ninja_build_writer.cc
+++ b/tools/gn/ninja_build_writer.cc
@@ -242,7 +242,7 @@
 }
 
 void NinjaBuildWriter::WriteSubninjas() {
-  for (const auto& elem : all_settings_) {
+  for (auto* elem : all_settings_) {
     out_ << "subninja ";
     path_output_.WriteFile(out_, GetNinjaFileForToolchain(elem));
     out_ << std::endl;
diff --git a/tools/gn/ninja_target_writer.cc b/tools/gn/ninja_target_writer.cc
index 7843d75..69e9d90 100644
--- a/tools/gn/ninja_target_writer.cc
+++ b/tools/gn/ninja_target_writer.cc
@@ -255,7 +255,7 @@
   std::sort(
       input_deps_targets.begin(), input_deps_targets.end(),
       [](const Target* a, const Target* b) { return a->label() < b->label(); });
-  for (const auto& dep : input_deps_targets) {
+  for (auto* dep : input_deps_targets) {
     DCHECK(!dep->dependency_output_file().value().empty());
     out_ << " ";
     path_output_.WriteFile(out_, dep->dependency_output_file());
diff --git a/tools/gn/ninja_toolchain_writer.cc b/tools/gn/ninja_toolchain_writer.cc
index 1deff58..9b699b8 100644
--- a/tools/gn/ninja_toolchain_writer.cc
+++ b/tools/gn/ninja_toolchain_writer.cc
@@ -136,7 +136,7 @@
 
 void NinjaToolchainWriter::WriteSubninjas() {
   // Write subninja commands for each generated target.
-  for (const auto& target : targets_) {
+  for (auto* target : targets_) {
     OutputFile ninja_file(target->settings()->build_settings(),
                           GetNinjaFileForTarget(target));
     out_ << "subninja ";
diff --git a/tools/gn/ninja_writer.cc b/tools/gn/ninja_writer.cc
index 7d26f48..22a97ec 100644
--- a/tools/gn/ninja_writer.cc
+++ b/tools/gn/ninja_writer.cc
@@ -58,7 +58,7 @@
   CategorizedMap categorized;
 
   std::vector<const BuilderRecord*> all_records = builder_->GetAllRecords();
-  for (const auto& all_record : all_records) {
+  for (auto* all_record : all_records) {
     if (all_record->type() == BuilderRecord::ITEM_TARGET &&
         all_record->should_generate()) {
       categorized[all_record->label().GetToolchainLabel()].push_back(
diff --git a/tools/gn/parse_tree_unittest.cc b/tools/gn/parse_tree_unittest.cc
index f5edbc8..a6850a7 100644
--- a/tools/gn/parse_tree_unittest.cc
+++ b/tools/gn/parse_tree_unittest.cc
@@ -225,7 +225,7 @@
       "9223372036854775807",   // INT64_MAX
       "-9223372036854775808",  // INT64_MIN
   };
-  for (auto s : kGood) {
+  for (auto* s : kGood) {
     TestParseInput input(std::string("x = ") + s);
     EXPECT_FALSE(input.has_error());
 
@@ -242,7 +242,7 @@
       "9223372036854775808",   // INT64_MAX + 1
       "-9223372036854775809",  // INT64_MIN - 1
   };
-  for (auto s : kBad) {
+  for (auto* s : kBad) {
     TestParseInput input(std::string("x = ") + s);
     EXPECT_FALSE(input.has_error());
 
diff --git a/tools/gn/parser.cc b/tools/gn/parser.cc
index 977ddad..7e5886f 100644
--- a/tools/gn/parser.cc
+++ b/tools/gn/parser.cc
@@ -711,7 +711,7 @@
 
   // Assign line comments to syntax immediately following.
   int cur_comment = 0;
-  for (const auto& node : pre) {
+  for (auto* node : pre) {
     const Location& start = node->GetRange().begin();
     while (cur_comment < static_cast<int>(line_comment_tokens_.size())) {
       if (start.byte() >= line_comment_tokens_[cur_comment].location().byte()) {
diff --git a/tools/gn/scope.cc b/tools/gn/scope.cc
index 93ce966..3869f3b 100644
--- a/tools/gn/scope.cc
+++ b/tools/gn/scope.cc
@@ -69,7 +69,7 @@
 const Value* Scope::GetValue(const base::StringPiece& ident,
                              bool counts_as_used) {
   // First check for programmatically-provided values.
-  for (const auto& provider : programmatic_providers_) {
+  for (auto* provider : programmatic_providers_) {
     const Value* v = provider->GetProgrammaticValue(ident);
     if (v)
       return v;
diff --git a/tools/gn/target.cc b/tools/gn/target.cc
index afcde09..aa1fcf6 100644
--- a/tools/gn/target.cc
+++ b/tools/gn/target.cc
@@ -128,7 +128,7 @@
         return true;  // Found a path.
     }
     if (target->output_type() == Target::CREATE_BUNDLE) {
-      for (const auto& dep : target->bundle_data().bundle_deps()) {
+      for (auto* dep : target->bundle_data().bundle_deps()) {
         if (EnsureFileIsGeneratedByDependency(dep, file, false,
                                               consider_object_files,
                                               check_data_deps, seen_targets))
@@ -521,7 +521,7 @@
       bundle_data_.AddBundleData(pair.ptr);
 
     // Recursive bundle_data informations from all dependencies.
-    for (const auto& target : pair.ptr->bundle_data().bundle_deps())
+    for (auto* target : pair.ptr->bundle_data().bundle_deps())
       bundle_data_.AddBundleData(target);
   }
 
diff --git a/tools/gn/trace.cc b/tools/gn/trace.cc
index 13ebf62..2a1b460 100644
--- a/tools/gn/trace.cc
+++ b/tools/gn/trace.cc
@@ -70,7 +70,7 @@
   out << "File parse times: (time in ms, name)\n";
 
   std::sort(loads.begin(), loads.end(), &DurationGreater);
-  for (const auto& load : loads) {
+  for (auto* load : loads) {
     out << base::StringPrintf(" %8.2f  ", load->delta().InMillisecondsF());
     out << load->name() << std::endl;
   }
@@ -80,7 +80,7 @@
                         std::ostream& out) {
   // Group by file name.
   std::map<std::string, Coalesced> coalesced;
-  for (const auto& item : items) {
+  for (auto* item : items) {
     Coalesced& c = coalesced[item->name()];
     c.name_ptr = &item->name();
     c.total_duration += item->delta().InMillisecondsF();
@@ -186,7 +186,7 @@
   std::vector<const TraceItem*> script_execs;
   std::vector<const TraceItem*> check_headers;
   int headers_checked = 0;
-  for (const auto& event : events) {
+  for (auto* event : events) {
     switch (event->type()) {
       case TraceItem::TRACE_FILE_PARSE:
         parses.push_back(event);
@@ -225,7 +225,7 @@
   // parallel. Just report the total of all of them.
   if (!check_headers.empty()) {
     double check_headers_time = 0;
-    for (const auto& cur : check_headers)
+    for (auto* cur : check_headers)
       check_headers_time += cur->delta().InMillisecondsF();
 
     out << "Header check time: (total time in ms, files checked)\n";
diff --git a/tools/gn/xcode_writer.cc b/tools/gn/xcode_writer.cc
index e076339..d60f4f7 100644
--- a/tools/gn/xcode_writer.cc
+++ b/tools/gn/xcode_writer.cc
@@ -419,7 +419,7 @@
               [](const PBXObject* a, const PBXObject* b) {
                 return a->id() < b->id();
               });
-    for (const auto& object : pair.second) {
+    for (auto* object : pair.second) {
       object->Print(out, 2);
     }
     out << "/* End " << ToString(pair.first) << " section */\n";