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

Fix shadowing warnings #8926

Merged
merged 1 commit into from Sep 13, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/google/protobuf/compiler/command_line_interface.cc
Expand Up @@ -2423,8 +2423,8 @@ bool CommandLineInterface::WriteDescriptorSet(
to_output.insert(parsed_files.begin(), parsed_files.end());
for (int i = 0; i < parsed_files.size(); i++) {
const FileDescriptor* file = parsed_files[i];
for (int i = 0; i < file->dependency_count(); i++) {
const FileDescriptor* dependency = file->dependency(i);
for (int j = 0; j < file->dependency_count(); j++) {
const FileDescriptor* dependency = file->dependency(j);
// if the dependency isn't in parsed files, mark it as already seen
if (to_output.find(dependency) == to_output.end()) {
already_seen.insert(dependency);
Expand Down
4 changes: 2 additions & 2 deletions src/google/protobuf/compiler/cpp/cpp_file.cc
Expand Up @@ -154,8 +154,8 @@ void FileGenerator::GenerateMacroUndefs(io::Printer* printer) {
for (int i = 0; i < fields.size(); i++) {
const std::string& name = fields[i]->name();
static const char* kMacroNames[] = {"major", "minor"};
for (int i = 0; i < GOOGLE_ARRAYSIZE(kMacroNames); ++i) {
if (name == kMacroNames[i]) {
for (int j = 0; j < GOOGLE_ARRAYSIZE(kMacroNames); ++j) {
if (name == kMacroNames[j]) {
names_to_undef.push_back(name);
break;
}
Expand Down
4 changes: 2 additions & 2 deletions src/google/protobuf/compiler/cpp/cpp_helpers.cc
Expand Up @@ -1158,8 +1158,8 @@ MessageAnalysis MessageSCCAnalyzer::GetSCCAnalysis(const SCC* scc) {
if (descriptor->extension_range_count() > 0) {
result.contains_extension = true;
}
for (int i = 0; i < descriptor->field_count(); i++) {
const FieldDescriptor* field = descriptor->field(i);
for (int j = 0; j < descriptor->field_count(); j++) {
const FieldDescriptor* field = descriptor->field(j);
if (field->is_required()) {
result.contains_required = true;
}
Expand Down
6 changes: 3 additions & 3 deletions src/google/protobuf/compiler/cpp/cpp_service.cc
Expand Up @@ -241,12 +241,12 @@ void ServiceGenerator::GenerateCallMethod(io::Printer* printer) {

for (int i = 0; i < descriptor_->method_count(); i++) {
const MethodDescriptor* method = descriptor_->method(i);
Formatter format(printer, vars_);
InitMethodVariables(method, options_, &format);
Formatter format_method(printer, vars_);
InitMethodVariables(method, options_, &format_method);

// Note: down_cast does not work here because it only works on pointers,
// not references.
format(
format_method(
" case $1$:\n"
" $name$(controller,\n"
" ::$proto_ns$::internal::DownCast<const $input_type$*>(\n"
Expand Down
1 change: 0 additions & 1 deletion src/google/protobuf/compiler/objectivec/objectivec_enum.cc
Expand Up @@ -127,7 +127,6 @@ void EnumGenerator::GenerateHeader(io::Printer* printer) {
if (alias_values_to_skip_.find(all_values_[i]) != alias_values_to_skip_.end()) {
continue;
}
SourceLocation location;
if (all_values_[i]->GetSourceLocation(&location)) {
std::string comments = BuildCommentsString(location, true).c_str();
if (comments.length() > 0) {
Expand Down
12 changes: 6 additions & 6 deletions src/google/protobuf/compiler/php/php_generator.cc
Expand Up @@ -1119,9 +1119,9 @@ void GenerateAddFilesToPool(const FileDescriptor* file, const Options& options,
file, &nodes_without_dependency, &deps, &dependency_count);

while (!nodes_without_dependency.empty()) {
auto file = *nodes_without_dependency.begin();
nodes_without_dependency.erase(file);
for (auto dependent : deps[file]) {
auto file_node = *nodes_without_dependency.begin();
nodes_without_dependency.erase(file_node);
for (auto dependent : deps[file_node]) {
if (dependency_count[dependent] == 1) {
dependency_count.erase(dependent);
nodes_without_dependency.insert(dependent);
Expand All @@ -1130,11 +1130,11 @@ void GenerateAddFilesToPool(const FileDescriptor* file, const Options& options,
}
}

bool needs_aggregate = NeedsUnwrapping(file, options);
bool needs_aggregate = NeedsUnwrapping(file_node, options);

if (needs_aggregate) {
auto file_proto = sorted_file_set.add_file();
file->CopyTo(file_proto);
file_node->CopyTo(file_proto);

// Filter out descriptor.proto as it cannot be depended on for now.
RepeatedPtrField<std::string>* dependency =
Expand All @@ -1156,7 +1156,7 @@ void GenerateAddFilesToPool(const FileDescriptor* file, const Options& options,
it->clear_extension();
}
} else {
std::string dependency_filename = GeneratedMetadataFileName(file, false);
std::string dependency_filename = GeneratedMetadataFileName(file_node, false);
printer->Print(
"\\^name^::initOnce();\n",
"name", FilenameToClassname(dependency_filename));
Expand Down
4 changes: 2 additions & 2 deletions src/google/protobuf/compiler/python/python_generator.cc
Expand Up @@ -780,11 +780,11 @@ void Generator::PrintDescriptor(const Descriptor& message_descriptor) const {
printer_->Indent();
for (int i = 0; i < message_descriptor.oneof_decl_count(); ++i) {
const OneofDescriptor* desc = message_descriptor.oneof_decl(i);
std::map<std::string, std::string> m;
m.clear();
m["name"] = desc->name();
m["full_name"] = desc->full_name();
m["index"] = StrCat(desc->index());
std::string options_string =
options_string =
OptionsValue(desc->options().SerializeAsString());
if (options_string == "None") {
m["serialized_options"] = "";
Expand Down
4 changes: 2 additions & 2 deletions src/google/protobuf/dynamic_message.cc
Expand Up @@ -747,9 +747,9 @@ const Message* DynamicMessageFactory::GetPrototypeNoLock(
// hasbits.
type_info->has_bits_offset = size;
uint32_t* has_bits_indices = new uint32_t[type->field_count()];
for (int i = 0; i < type->field_count(); i++) {
for (int j = 0; j < type->field_count(); j++) {
// Initialize to -1, fields that need a hasbit will overwrite.
has_bits_indices[i] = static_cast<uint32_t>(-1);
has_bits_indices[j] = static_cast<uint32_t>(-1);
}
type_info->has_bits_indices.reset(has_bits_indices);
}
Expand Down
8 changes: 4 additions & 4 deletions src/google/protobuf/generated_message_util.cc
Expand Up @@ -701,13 +701,13 @@ uint8_t* SerializeInternalToArray(const uint8_t* base,
// Special cases
case FieldMetadata::kSpecial: {
io::ArrayOutputStream array_stream(array_output.ptr, INT_MAX);
io::CodedOutputStream output(&array_stream);
output.SetSerializationDeterministic(is_deterministic);
io::CodedOutputStream output_stream(&array_stream);
output_stream.SetSerializationDeterministic(is_deterministic);
func = reinterpret_cast<SpecialSerializer>(
const_cast<void*>(field_metadata.ptr));
func(base, field_metadata.offset, field_metadata.tag,
field_metadata.has_offset, &output);
array_output.ptr += output.ByteCount();
field_metadata.has_offset, &output_stream);
array_output.ptr += output_stream.ByteCount();
} break;
default:
// __builtin_unreachable()
Expand Down
6 changes: 3 additions & 3 deletions src/google/protobuf/reflection_ops.cc
Expand Up @@ -214,9 +214,9 @@ bool ReflectionOps::IsInitialized(const Message& message, bool check_fields,
reflection->GetMapData(message, field);
if (map_field->IsMapValid()) {
MapIterator it(const_cast<Message*>(&message), field);
MapIterator end(const_cast<Message*>(&message), field);
for (map_field->MapBegin(&it), map_field->MapEnd(&end);
it != end; ++it) {
MapIterator end_map(const_cast<Message*>(&message), field);
for (map_field->MapBegin(&it), map_field->MapEnd(&end_map);
it != end_map; ++it) {
if (!it.GetValueRef().GetMessageValue().IsInitialized()) {
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions src/google/protobuf/stubs/strutil.cc
Expand Up @@ -1272,7 +1272,7 @@ char* DoubleToBuffer(double value, char* buffer) {
// truncated to a double.
volatile double parsed_value = internal::NoLocaleStrtod(buffer, nullptr);
if (parsed_value != value) {
int snprintf_result =
snprintf_result =
snprintf(buffer, kDoubleToBufferSize, "%.*g", DBL_DIG+2, value);

// Should never overflow; see above.
Expand Down Expand Up @@ -1384,7 +1384,7 @@ char* FloatToBuffer(float value, char* buffer) {

float parsed_value;
if (!safe_strtof(buffer, &parsed_value) || parsed_value != value) {
int snprintf_result =
snprintf_result =
snprintf(buffer, kFloatToBufferSize, "%.*g", FLT_DIG+3, value);

// Should never overflow; see above.
Expand Down
4 changes: 2 additions & 2 deletions src/google/protobuf/util/field_mask_util.cc
Expand Up @@ -385,8 +385,8 @@ void FieldMaskTree::RemovePath(const std::string& path,
if (new_branch_node == nullptr) {
new_branch_node = node;
}
for (int i = 0; i < current_descriptor->field_count(); ++i) {
node->children[current_descriptor->field(i)->name()] = new Node();
for (int j = 0; j < current_descriptor->field_count(); ++j) {
node->children[current_descriptor->field(j)->name()] = new Node();
}
}
if (ContainsKey(node->children, parts[i])) {
Expand Down
12 changes: 6 additions & 6 deletions src/google/protobuf/util/internal/protostream_objectsource.cc
Expand Up @@ -265,16 +265,16 @@ util::StatusOr<uint32_t> ProtoStreamObjectSource::RenderMap(
std::string map_key;
for (uint32_t tag = stream_->ReadTag(); tag != 0;
tag = stream_->ReadTag()) {
const google::protobuf::Field* field =
const google::protobuf::Field* map_entry_field =
FindAndVerifyField(*field_type, tag);
if (field == nullptr) {
if (map_entry_field == nullptr) {
WireFormat::SkipField(stream_, tag, nullptr);
continue;
}
// Map field numbers are key = 1 and value = 2
if (field->number() == 1) {
map_key = ReadFieldValueAsString(*field);
} else if (field->number() == 2) {
if (map_entry_field->number() == 1) {
map_key = ReadFieldValueAsString(*map_entry_field);
} else if (map_entry_field->number() == 2) {
if (map_key.empty()) {
// An absent map key is treated as the default.
const google::protobuf::Field* key_field =
Expand All @@ -286,7 +286,7 @@ util::StatusOr<uint32_t> ProtoStreamObjectSource::RenderMap(
}
ASSIGN_OR_RETURN(map_key, MapKeyDefaultValueAsString(*key_field));
}
RETURN_IF_ERROR(RenderField(field, map_key, ow));
RETURN_IF_ERROR(RenderField(map_entry_field, map_key, ow));
} else {
// The Type info for this map entry is incorrect. It should contain
// exactly two fields with field number 1 and 2.
Expand Down