Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion explorer/syntax/parse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
6 changes: 3 additions & 3 deletions migrate_cpp/cpp_refactoring/matcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion testing/base/source_gen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())];
Expand Down
6 changes: 3 additions & 3 deletions toolchain/base/value_store.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,15 @@ 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;
}

// 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;
}
Expand All @@ -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)));
}
});
Expand Down
4 changes: 2 additions & 2 deletions toolchain/check/import_ref.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
14 changes: 7 additions & 7 deletions toolchain/check/subst.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion toolchain/lex/lex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions toolchain/parse/handle_import_and_package.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
8 changes: 4 additions & 4 deletions toolchain/sem_ir/inst_namer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down
Loading