From d4a5c98b2c2cca08223d3d58a0f681dc88f0c626 Mon Sep 17 00:00:00 2001 From: David Blaikie Date: Thu, 22 Aug 2024 20:02:32 +0000 Subject: [PATCH] Remove excess use of auto on initializers (auto x = Y(z) -> Y x(z)) --- explorer/syntax/parse.cpp | 2 +- migrate_cpp/cpp_refactoring/matcher.cpp | 6 +++--- testing/base/source_gen.cpp | 2 +- toolchain/base/value_store.h | 6 +++--- toolchain/check/import_ref.cpp | 4 ++-- toolchain/check/subst.cpp | 14 +++++++------- toolchain/lex/lex.cpp | 2 +- toolchain/parse/handle_import_and_package.cpp | 3 +-- toolchain/sem_ir/inst_namer.cpp | 8 ++++---- 9 files changed, 23 insertions(+), 24 deletions(-) diff --git a/explorer/syntax/parse.cpp b/explorer/syntax/parse.cpp index 51472e0f99200..91882c63ec0ad 100644 --- a/explorer/syntax/parse.cpp +++ b/explorer/syntax/parse.cpp @@ -22,7 +22,7 @@ static auto ParseImpl(yyscan_t scanner, Nonnull 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); } diff --git a/migrate_cpp/cpp_refactoring/matcher.cpp b/migrate_cpp/cpp_refactoring/matcher.cpp index 177746a9ec336..12891df58f33f 100644 --- a/migrate_cpp/cpp_refactoring/matcher.cpp +++ b/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 diff --git a/testing/base/source_gen.cpp b/testing/base/source_gen.cpp index 31543c9dbe2c1..18636a1d305fb 100644 --- a/testing/base/source_gen.cpp +++ b/testing/base/source_gen.cpp @@ -243,7 +243,7 @@ auto SourceGen::GenerateRandomIdentifier( llvm::ArrayRef start_chars = IdentifierStartChars(); llvm::ArrayRef 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(rng_, 0, start_chars.size())]; diff --git a/toolchain/base/value_store.h b/toolchain/base/value_store.h index 5dacf8116f133..010362df76369 100644 --- a/toolchain/base/value_store.h +++ b/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))); } }); diff --git a/toolchain/check/import_ref.cpp b/toolchain/check/import_ref.cpp index 0dd640f93abdb..95b236ee2b0bd 100644 --- a/toolchain/check/import_ref.cpp +++ b/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); } } diff --git a/toolchain/check/subst.cpp b/toolchain/check/subst.cpp index 11203f98f7e98..adff7307b9f0c 100644 --- a/toolchain/check/subst.cpp +++ b/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: - 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: - 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: { - 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: { - 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: { - 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: { - 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: { - auto specific_id = SemIR::SpecificId(arg); + SemIR::SpecificId specific_id(arg); if (!specific_id.is_valid()) { return arg; } diff --git a/toolchain/lex/lex.cpp b/toolchain/lex/lex.cpp index 44cfe93bf4f68..442de6ad987bd 100644 --- a/toolchain/lex/lex.cpp +++ b/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, diff --git a/toolchain/parse/handle_import_and_package.cpp b/toolchain/parse/handle_import_and_package.cpp index f60f649b14e55..7b14fcde0c041 100644 --- a/toolchain/parse/handle_import_and_package.cpp +++ b/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; } diff --git a/toolchain/sem_ir/inst_namer.cpp b/toolchain/sem_ir/inst_namer.cpp index 3dffeb96814d0..3cbad8dc635dc 100644 --- a/toolchain/sem_ir/inst_namer.cpp +++ b/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;