Skip to content

Commit

Permalink
Merge pull request protocolbuffers#3018 from acozzette/using-namespac…
Browse files Browse the repository at this point in the history
…e-std

Remove "using namespace std" from stubs/common.h
  • Loading branch information
Adam Cozzette authored Apr 26, 2017
2 parents 54d1701 + 7c76ac1 commit cbd08cb
Show file tree
Hide file tree
Showing 15 changed files with 108 additions and 98 deletions.
12 changes: 6 additions & 6 deletions src/google/protobuf/compiler/command_line_interface.cc
Original file line number Diff line number Diff line change
Expand Up @@ -804,8 +804,8 @@ int CommandLineInterface::Run(int argc, const char* const argv[]) {

// Enforce --disallow_services.
if (disallow_services_ && parsed_file->service_count() > 0) {
cerr << parsed_file->name() << ": This file contains services, but "
"--disallow_services was used." << endl;
std::cerr << parsed_file->name() << ": This file contains services, but "
"--disallow_services was used." << std::endl;
return 1;
}

Expand All @@ -816,7 +816,7 @@ int CommandLineInterface::Run(int argc, const char* const argv[]) {
if (direct_dependencies_.find(parsed_file->dependency(i)->name()) ==
direct_dependencies_.end()) {
indirect_imports = true;
cerr << parsed_file->name() << ": "
std::cerr << parsed_file->name() << ": "
<< StringReplace(direct_dependencies_violation_msg_, "%s",
parsed_file->dependency(i)->name(),
true /* replace_all */)
Expand Down Expand Up @@ -1221,7 +1221,7 @@ CommandLineInterface::InterpretArgument(const string& name,
if (access(disk_path.c_str(), F_OK) < 0) {
// Try the original path; it may have just happed to have a '=' in it.
if (access(parts[i].c_str(), F_OK) < 0) {
cerr << disk_path << ": warning: directory does not exist." << endl;
std::cerr << disk_path << ": warning: directory does not exist." << std::endl;
} else {
virtual_path = "";
disk_path = parts[i];
Expand Down Expand Up @@ -1302,9 +1302,9 @@ CommandLineInterface::InterpretArgument(const string& name,
if (!version_info_.empty()) {
std::cout << version_info_ << std::endl;
}
cout << "libprotoc "
std::cout << "libprotoc "
<< protobuf::internal::VersionString(GOOGLE_PROTOBUF_VERSION)
<< endl;
<< std::endl;
return PARSE_ARGUMENT_DONE_AND_EXIT; // Exit without running compiler.

} else if (name == "--disallow_services") {
Expand Down
8 changes: 4 additions & 4 deletions src/google/protobuf/compiler/csharp/csharp_field_base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -322,9 +322,9 @@ std::string FieldGeneratorBase::default_value(const FieldDescriptor* descriptor)
}
case FieldDescriptor::TYPE_DOUBLE: {
double value = descriptor->default_value_double();
if (value == numeric_limits<double>::infinity()) {
if (value == std::numeric_limits<double>::infinity()) {
return "double.PositiveInfinity";
} else if (value == -numeric_limits<double>::infinity()) {
} else if (value == -std::numeric_limits<double>::infinity()) {
return "double.NegativeInfinity";
} else if (MathLimits<double>::IsNaN(value)) {
return "double.NaN";
Expand All @@ -333,9 +333,9 @@ std::string FieldGeneratorBase::default_value(const FieldDescriptor* descriptor)
}
case FieldDescriptor::TYPE_FLOAT: {
float value = descriptor->default_value_float();
if (value == numeric_limits<float>::infinity()) {
if (value == std::numeric_limits<float>::infinity()) {
return "float.PositiveInfinity";
} else if (value == -numeric_limits<float>::infinity()) {
} else if (value == -std::numeric_limits<float>::infinity()) {
return "float.NegativeInfinity";
} else if (MathLimits<float>::IsNaN(value)) {
return "float.NaN";
Expand Down
6 changes: 3 additions & 3 deletions src/google/protobuf/compiler/javanano/javanano_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,12 @@ bool FileGenerator::Validate(string* error) {
if (!params_.has_java_outer_classname(file_->name())
&& file_->message_type_count() == 1
&& file_->enum_type_count() == 0 && file_->extension_count() == 0) {
cout << "INFO: " << file_->name() << ":" << endl;
cout << "Javanano generator has changed to align with java generator. "
std::cout << "INFO: " << file_->name() << ":" << std::endl;
std::cout << "Javanano generator has changed to align with java generator. "
"An outer class will be created for this file and the single message "
"in the file will become a nested class. Use java_multiple_files to "
"skip generating the outer class, or set an explicit "
"java_outer_classname to suppress this message." << endl;
"java_outer_classname to suppress this message." << std::endl;
}

// Check that no class name matches the file's class name. This is a common
Expand Down
8 changes: 4 additions & 4 deletions src/google/protobuf/compiler/javanano/javanano_helpers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -428,9 +428,9 @@ string DefaultValue(const Params& params, const FieldDescriptor* field) {
"L";
case FieldDescriptor::CPPTYPE_DOUBLE: {
double value = field->default_value_double();
if (value == numeric_limits<double>::infinity()) {
if (value == std::numeric_limits<double>::infinity()) {
return "Double.POSITIVE_INFINITY";
} else if (value == -numeric_limits<double>::infinity()) {
} else if (value == -std::numeric_limits<double>::infinity()) {
return "Double.NEGATIVE_INFINITY";
} else if (value != value) {
return "Double.NaN";
Expand All @@ -440,9 +440,9 @@ string DefaultValue(const Params& params, const FieldDescriptor* field) {
}
case FieldDescriptor::CPPTYPE_FLOAT: {
float value = field->default_value_float();
if (value == numeric_limits<float>::infinity()) {
if (value == std::numeric_limits<float>::infinity()) {
return "Float.POSITIVE_INFINITY";
} else if (value == -numeric_limits<float>::infinity()) {
} else if (value == -std::numeric_limits<float>::infinity()) {
return "Float.NEGATIVE_INFINITY";
} else if (value != value) {
return "Float.NaN";
Expand Down
2 changes: 1 addition & 1 deletion src/google/protobuf/compiler/javanano/javanano_message.cc
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ const FieldDescriptor** SortFieldsByNumber(const Descriptor* descriptor) {
for (int i = 0; i < descriptor->field_count(); i++) {
fields[i] = descriptor->field(i);
}
sort(fields, fields + descriptor->field_count(),
std::sort(fields, fields + descriptor->field_count(),
FieldOrderingByNumber());
return fields;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ ExtensionGenerator::ExtensionGenerator(const string& root_class_name,
if (descriptor->is_map()) {
// NOTE: src/google/protobuf/compiler/plugin.cc makes use of cerr for some
// error cases, so it seems to be ok to use as a back door for errors.
cerr << "error: Extension is a map<>!"
<< " That used to be blocked by the compiler." << endl;
cerr.flush();
std::cerr << "error: Extension is a map<>!"
<< " That used to be blocked by the compiler." << std::endl;
std::cerr.flush();
abort();
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/google/protobuf/compiler/objectivec/objectivec_field.cc
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,8 @@ int FieldGenerator::ExtraRuntimeHasBitsNeeded(void) const {
void FieldGenerator::SetExtraRuntimeHasBitsBase(int index_base) {
// NOTE: src/google/protobuf/compiler/plugin.cc makes use of cerr for some
// error cases, so it seems to be ok to use as a back door for errors.
cerr << "Error: should have overridden SetExtraRuntimeHasBitsBase()." << endl;
cerr.flush();
std::cerr << "Error: should have overridden SetExtraRuntimeHasBitsBase()." << std::endl;
std::cerr.flush();
abort();
}

Expand Down
68 changes: 34 additions & 34 deletions src/google/protobuf/compiler/objectivec/objectivec_helpers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1063,21 +1063,21 @@ bool ValidateObjCClassPrefix(
// to Apple's rules (the checks above implicitly whitelist anything that
// doesn't meet these rules).
if (!ascii_isupper(prefix[0])) {
cerr << endl
std::cerr << std::endl
<< "protoc:0: warning: Invalid 'option objc_class_prefix = \""
<< prefix << "\";' in '" << file->name() << "';"
<< " it should start with a capital letter." << endl;
cerr.flush();
<< " it should start with a capital letter." << std::endl;
std::cerr.flush();
}
if (prefix.length() < 3) {
// Apple reserves 2 character prefixes for themselves. They do use some
// 3 character prefixes, but they haven't updated the rules/docs.
cerr << endl
std::cerr << std::endl
<< "protoc:0: warning: Invalid 'option objc_class_prefix = \""
<< prefix << "\";' in '" << file->name() << "';"
<< " Apple recommends they should be at least 3 characters long."
<< endl;
cerr.flush();
<< std::endl;
std::cerr.flush();
}

// Look for any other package that uses the same prefix.
Expand All @@ -1096,22 +1096,22 @@ bool ValidateObjCClassPrefix(
// The file does not have a package and ...
if (other_package_for_prefix.empty()) {
// ... no other package has declared that prefix.
cerr << endl
std::cerr << std::endl
<< "protoc:0: warning: File '" << file->name() << "' has no "
<< "package. Consider adding a new package to the proto and adding '"
<< "new.package = " << prefix << "' to the expected prefixes file ("
<< expected_prefixes_path << ")." << endl;
cerr.flush();
<< expected_prefixes_path << ")." << std::endl;
std::cerr.flush();
} else {
// ... another package has declared the same prefix.
cerr << endl
std::cerr << std::endl
<< "protoc:0: warning: File '" << file->name() << "' has no package "
<< "and package '" << other_package_for_prefix << "' already uses '"
<< prefix << "' as its prefix. Consider either adding a new package "
<< "to the proto, or reusing one of the packages already using this "
<< "prefix in the expected prefixes file ("
<< expected_prefixes_path << ")." << endl;
cerr.flush();
<< expected_prefixes_path << ")." << std::endl;
std::cerr.flush();
}
return true;
}
Expand All @@ -1133,12 +1133,12 @@ bool ValidateObjCClassPrefix(
// Check: Warning - If the given package/prefix pair wasn't expected, issue a
// warning issue a warning suggesting it gets added to the file.
if (!expected_package_prefixes.empty()) {
cerr << endl
std::cerr << std::endl
<< "protoc:0: warning: Found unexpected 'option objc_class_prefix = \""
<< prefix << "\";' in '" << file->name() << "';"
<< " consider adding it to the expected prefixes file ("
<< expected_prefixes_path << ")." << endl;
cerr.flush();
<< expected_prefixes_path << ")." << std::endl;
std::cerr.flush();
}

return true;
Expand Down Expand Up @@ -1180,10 +1180,10 @@ void TextFormatDecodeData::AddString(int32 key,
for (vector<DataEntry>::const_iterator i = entries_.begin();
i != entries_.end(); ++i) {
if (i->first == key) {
cerr << "error: duplicate key (" << key
std::cerr << "error: duplicate key (" << key
<< ") making TextFormat data, input: \"" << input_for_decode
<< "\", desired: \"" << desired_output << "\"." << endl;
cerr.flush();
<< "\", desired: \"" << desired_output << "\"." << std::endl;
std::cerr.flush();
abort();
}
}
Expand All @@ -1194,7 +1194,7 @@ void TextFormatDecodeData::AddString(int32 key,
}

string TextFormatDecodeData::Data() const {
ostringstream data_stringstream;
std::ostringstream data_stringstream;

if (num_entries() > 0) {
io::OstreamOutputStream data_outputstream(&data_stringstream);
Expand Down Expand Up @@ -1335,18 +1335,18 @@ string DirectDecodeString(const string& str) {
string TextFormatDecodeData::DecodeDataForString(const string& input_for_decode,
const string& desired_output) {
if ((input_for_decode.size() == 0) || (desired_output.size() == 0)) {
cerr << "error: got empty string for making TextFormat data, input: \""
std::cerr << "error: got empty string for making TextFormat data, input: \""
<< input_for_decode << "\", desired: \"" << desired_output << "\"."
<< endl;
cerr.flush();
<< std::endl;
std::cerr.flush();
abort();
}
if ((input_for_decode.find('\0') != string::npos) ||
(desired_output.find('\0') != string::npos)) {
cerr << "error: got a null char in a string for making TextFormat data,"
std::cerr << "error: got a null char in a string for making TextFormat data,"
<< " input: \"" << CEscape(input_for_decode) << "\", desired: \""
<< CEscape(desired_output) << "\"." << endl;
cerr.flush();
<< CEscape(desired_output) << "\"." << std::endl;
std::cerr.flush();
abort();
}

Expand Down Expand Up @@ -1611,9 +1611,9 @@ void ImportWriter::ParseFrameworkMappings() {
string parse_error;
if (!ParseSimpleFile(named_framework_to_proto_path_mappings_path_,
&collector, &parse_error)) {
cerr << "error parsing " << named_framework_to_proto_path_mappings_path_
<< " : " << parse_error << endl;
cerr.flush();
std::cerr << "error parsing " << named_framework_to_proto_path_mappings_path_
<< " : " << parse_error << std::endl;
std::cerr.flush();
}
}

Expand Down Expand Up @@ -1643,16 +1643,16 @@ bool ImportWriter::ProtoFrameworkCollector::ConsumeLine(
map<string, string>::iterator existing_entry =
map_->find(proto_file.ToString());
if (existing_entry != map_->end()) {
cerr << "warning: duplicate proto file reference, replacing framework entry for '"
std::cerr << "warning: duplicate proto file reference, replacing framework entry for '"
<< proto_file.ToString() << "' with '" << framework_name.ToString()
<< "' (was '" << existing_entry->second << "')." << endl;
cerr.flush();
<< "' (was '" << existing_entry->second << "')." << std::endl;
std::cerr.flush();
}

if (proto_file.find(' ') != StringPiece::npos) {
cerr << "note: framework mapping file had a proto file with a space in, hopefully that isn't a missing comma: '"
<< proto_file.ToString() << "'" << endl;
cerr.flush();
std::cerr << "note: framework mapping file had a proto file with a space in, hopefully that isn't a missing comma: '"
<< proto_file.ToString() << "'" << std::endl;
std::cerr.flush();
}

(*map_)[proto_file.ToString()] = framework_name.ToString();
Expand Down
6 changes: 3 additions & 3 deletions src/google/protobuf/compiler/objectivec/objectivec_message.cc
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ const FieldDescriptor** SortFieldsByNumber(const Descriptor* descriptor) {
for (int i = 0; i < descriptor->field_count(); i++) {
fields[i] = descriptor->field(i);
}
sort(fields, fields + descriptor->field_count(), FieldOrderingByNumber());
std::sort(fields, fields + descriptor->field_count(), FieldOrderingByNumber());
return fields;
}

Expand All @@ -168,7 +168,7 @@ const FieldDescriptor** SortFieldsByStorageSize(const Descriptor* descriptor) {
for (int i = 0; i < descriptor->field_count(); i++) {
fields[i] = descriptor->field(i);
}
sort(fields, fields + descriptor->field_count(),
std::sort(fields, fields + descriptor->field_count(),
FieldOrderingByStorageSize());
return fields;
}
Expand Down Expand Up @@ -430,7 +430,7 @@ void MessageGenerator::GenerateSource(io::Printer* printer) {
sorted_extensions.push_back(descriptor_->extension_range(i));
}

sort(sorted_extensions.begin(), sorted_extensions.end(),
std::sort(sorted_extensions.begin(), sorted_extensions.end(),
ExtensionRangeOrdering());

// Assign has bits:
Expand Down
2 changes: 1 addition & 1 deletion src/google/protobuf/io/zero_copy_stream_impl_lite.h
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ inline std::pair<char*, bool> as_string_data(string* s) {
#ifdef LANG_CXX11
return std::make_pair(p, true);
#else
return make_pair(p, p != NULL);
return std::make_pair(p, p != NULL);
#endif
}

Expand Down
Loading

0 comments on commit cbd08cb

Please sign in to comment.