Selaa lähdekoodia

Remove excess use of auto on initializers (auto x = Y(z) -> Y x(z)) (#4239)

David Blaikie 1 vuosi sitten
vanhempi
sitoutus
a17480133f

+ 1 - 1
explorer/syntax/parse.cpp

@@ -22,7 +22,7 @@ static auto ParseImpl(yyscan_t scanner, Nonnull<Arena*> arena,
                              file_kind, parser_debug);
 
   // Do the parse.
-  auto parser = Parser(arena, scanner, context, &ast);
+  Parser parser(arena, scanner, context, &ast);
   if (parser_debug) {
     parser.set_debug_level(1);
   }

+ 3 - 3
migrate_cpp/cpp_refactoring/matcher.cpp

@@ -26,9 +26,9 @@ void Matcher::AddReplacement(clang::CharSourceRange range,
     return;
   }
 
-  auto rep = clang::tooling::Replacement(
-      source_manager, source_manager.getExpansionRange(range),
-      replacement_text);
+  clang::tooling::Replacement rep(source_manager,
+                                  source_manager.getExpansionRange(range),
+                                  replacement_text);
   auto entry = replacements->find(std::string(rep.getFilePath()));
   if (entry == replacements->end()) {
     // The replacement was in a file which isn't being updated, such as a system

+ 1 - 1
testing/base/source_gen.cpp

@@ -243,7 +243,7 @@ auto SourceGen::GenerateRandomIdentifier(
   llvm::ArrayRef<char> start_chars = IdentifierStartChars();
   llvm::ArrayRef<char> chars = IdentifierChars();
 
-  auto ident = llvm::StringRef(dest_storage.data(), dest_storage.size());
+  llvm::StringRef ident(dest_storage.data(), dest_storage.size());
   do {
     dest_storage[0] =
         start_chars[absl::Uniform<int>(rng_, 0, start_chars.size())];

+ 3 - 3
toolchain/base/value_store.h

@@ -150,7 +150,7 @@ class ValueStore
 
   // Stores the value and returns an ID to reference it.
   auto Add(ValueType value) -> IdT {
-    IdT id = IdT(values_.size());
+    IdT id(values_.size());
     CARBON_CHECK(id.index >= 0) << "Id overflow";
     values_.push_back(std::move(value));
     return id;
@@ -158,7 +158,7 @@ class ValueStore
 
   // Adds a default constructed value and returns an ID to reference it.
   auto AddDefaultValue() -> IdT {
-    auto id = IdT(values_.size());
+    IdT id(values_.size());
     values_.resize(id.index + 1);
     return id;
   }
@@ -182,7 +182,7 @@ class ValueStore
   auto OutputYaml() const -> Yaml::OutputMapping {
     return Yaml::OutputMapping([&](Yaml::OutputMapping::Map map) {
       for (auto i : llvm::seq(values_.size())) {
-        auto id = IdT(i);
+        IdT id(i);
         map.Add(PrintToString(id), Yaml::OutputScalar(Get(id)));
       }
     });

+ 2 - 2
toolchain/check/import_ref.cpp

@@ -2059,9 +2059,9 @@ auto ImportImpls(Context& context) -> void {
       continue;
     }
 
-    auto import_ir_id = SemIR::ImportIRId(import_index);
+    SemIR::ImportIRId import_ir_id(import_index);
     for (auto impl_index : llvm::seq(import_ir.sem_ir->impls().size())) {
-      auto impl_id = SemIR::ImplId(impl_index);
+      SemIR::ImplId impl_id(impl_index);
       ImportImpl(context, import_ir_id, *import_ir.sem_ir, impl_id);
     }
   }

+ 7 - 7
toolchain/check/subst.cpp

@@ -63,12 +63,12 @@ static auto PushOperand(Context& context, Worklist& worklist,
                         SemIR::IdKind kind, int32_t arg) -> void {
   switch (kind) {
     case SemIR::IdKind::For<SemIR::InstId>:
-      if (auto inst_id = SemIR::InstId(arg); inst_id.is_valid()) {
+      if (SemIR::InstId inst_id(arg); inst_id.is_valid()) {
         worklist.Push(inst_id);
       }
       break;
     case SemIR::IdKind::For<SemIR::TypeId>:
-      if (auto type_id = SemIR::TypeId(arg); type_id.is_valid()) {
+      if (SemIR::TypeId type_id(arg); type_id.is_valid()) {
         worklist.Push(context.types().GetInstId(type_id));
       }
       break;
@@ -111,21 +111,21 @@ static auto PopOperand(Context& context, Worklist& worklist, SemIR::IdKind kind,
                        int32_t arg) -> int32_t {
   switch (kind) {
     case SemIR::IdKind::For<SemIR::InstId>: {
-      auto inst_id = SemIR::InstId(arg);
+      SemIR::InstId inst_id(arg);
       if (!inst_id.is_valid()) {
         return arg;
       }
       return worklist.Pop().index;
     }
     case SemIR::IdKind::For<SemIR::TypeId>: {
-      auto type_id = SemIR::TypeId(arg);
+      SemIR::TypeId type_id(arg);
       if (!type_id.is_valid()) {
         return arg;
       }
       return context.GetTypeIdForTypeInst(worklist.Pop()).index;
     }
     case SemIR::IdKind::For<SemIR::InstBlockId>: {
-      auto old_inst_block_id = SemIR::InstBlockId(arg);
+      SemIR::InstBlockId old_inst_block_id(arg);
       auto size = context.inst_blocks().Get(old_inst_block_id).size();
       SemIR::CopyOnWriteInstBlock new_inst_block(context.sem_ir(),
                                                  old_inst_block_id);
@@ -135,7 +135,7 @@ static auto PopOperand(Context& context, Worklist& worklist, SemIR::IdKind kind,
       return new_inst_block.GetCanonical().index;
     }
     case SemIR::IdKind::For<SemIR::TypeBlockId>: {
-      auto old_type_block_id = SemIR::TypeBlockId(arg);
+      SemIR::TypeBlockId old_type_block_id(arg);
       auto size = context.type_blocks().Get(old_type_block_id).size();
       SemIR::CopyOnWriteTypeBlock new_type_block(context.sem_ir(),
                                                  old_type_block_id);
@@ -146,7 +146,7 @@ static auto PopOperand(Context& context, Worklist& worklist, SemIR::IdKind kind,
       return new_type_block.GetCanonical().index;
     }
     case SemIR::IdKind::For<SemIR::SpecificId>: {
-      auto specific_id = SemIR::SpecificId(arg);
+      SemIR::SpecificId specific_id(arg);
       if (!specific_id.is_valid()) {
         return arg;
       }

+ 1 - 1
toolchain/lex/lex.cpp

@@ -1335,7 +1335,7 @@ class Lexer::ErrorRecoveryBuffer {
 
     // Find the end of the token before the target token, and add the new token
     // there. Note that new_token_column is a 1-based column number.
-    auto insert_after = TokenIndex(insert_before.index - 1);
+    TokenIndex insert_after(insert_before.index - 1);
     auto [new_token_line, new_token_column] = buffer_.GetEndLoc(insert_after);
     new_tokens_.push_back(
         {insert_before,

+ 1 - 2
toolchain/parse/handle_import_and_package.cpp

@@ -25,8 +25,7 @@ static auto OnParseError(Context& context, Context::StateStackEntry state,
 // do this.
 static auto HasModifier(Context& context, Context::StateStackEntry state,
                         Lex::TokenKind modifier) -> bool {
-  for (auto it = Lex::TokenIterator(state.token); it != context.position();
-       ++it) {
+  for (Lex::TokenIterator it(state.token); it != context.position(); ++it) {
     if (context.tokens().GetKind(*it) == modifier) {
       return true;
     }

+ 4 - 4
toolchain/sem_ir/inst_namer.cpp

@@ -39,7 +39,7 @@ InstNamer::InstNamer(const Lex::TokenizedBuffer& tokenized_buffer,
 
   // Build each function scope.
   for (auto [i, fn] : llvm::enumerate(sem_ir.functions().array_ref())) {
-    auto fn_id = FunctionId(i);
+    FunctionId fn_id(i);
     auto fn_scope = GetScopeFor(fn_id);
     // TODO: Provide a location for the function for use as a
     // disambiguator.
@@ -68,7 +68,7 @@ InstNamer::InstNamer(const Lex::TokenizedBuffer& tokenized_buffer,
 
   // Build each class scope.
   for (auto [i, class_info] : llvm::enumerate(sem_ir.classes().array_ref())) {
-    auto class_id = ClassId(i);
+    ClassId class_id(i);
     auto class_scope = GetScopeFor(class_id);
     // TODO: Provide a location for the class for use as a disambiguator.
     auto class_loc = Parse::NodeId::Invalid;
@@ -83,7 +83,7 @@ InstNamer::InstNamer(const Lex::TokenizedBuffer& tokenized_buffer,
   // Build each interface scope.
   for (auto [i, interface_info] :
        llvm::enumerate(sem_ir.interfaces().array_ref())) {
-    auto interface_id = InterfaceId(i);
+    InterfaceId interface_id(i);
     auto interface_scope = GetScopeFor(interface_id);
     // TODO: Provide a location for the interface for use as a disambiguator.
     auto interface_loc = Parse::NodeId::Invalid;
@@ -98,7 +98,7 @@ InstNamer::InstNamer(const Lex::TokenizedBuffer& tokenized_buffer,
 
   // Build each impl scope.
   for (auto [i, impl_info] : llvm::enumerate(sem_ir.impls().array_ref())) {
-    auto impl_id = ImplId(i);
+    ImplId impl_id(i);
     auto impl_scope = GetScopeFor(impl_id);
     // TODO: Provide a location for the impl for use as a disambiguator.
     auto impl_loc = Parse::NodeId::Invalid;