From a63271c77f7ee4802761535f8c844f789328ad9f Mon Sep 17 00:00:00 2001
From: Vijay Pai <vpai@google.com>
Date: Wed, 15 Jun 2016 12:56:38 -0700
Subject: [PATCH] Deal with to_string, proper usage of nullptr, and lack of
 map::emplace

---
 include/grpc++/impl/codegen/config.h       | 12 ++++++++++++
 test/cpp/end2end/async_end2end_test.cc     |  4 ++--
 test/cpp/end2end/end2end_test.cc           | 12 ++++++------
 test/cpp/end2end/test_service_impl.cc      |  3 ++-
 test/cpp/end2end/thread_stress_test.cc     |  4 ++--
 test/cpp/util/metrics_server.cc            |  4 ++--
 test/cpp/util/test_credentials_provider.cc |  9 +--------
 7 files changed, 27 insertions(+), 21 deletions(-)

diff --git a/include/grpc++/impl/codegen/config.h b/include/grpc++/impl/codegen/config.h
index cf88efa1d1..0c75438868 100644
--- a/include/grpc++/impl/codegen/config.h
+++ b/include/grpc++/impl/codegen/config.h
@@ -54,6 +54,7 @@
 // nullptr was added in gcc 4.6
 #if (__GNUC__ * 100 + __GNUC_MINOR__ < 406)
 #define GRPC_CXX0X_NO_NULLPTR 1
+#define GRPC_CXX0X_LIMITED_TOSTRING 1
 #endif
 // final and override were added in gcc 4.7
 #if (__GNUC__ * 100 + __GNUC_MINOR__ < 407)
@@ -116,6 +117,17 @@ namespace grpc {
 
 typedef GRPC_CUSTOM_STRING string;
 
+#ifdef GRPC_CXX0X_LIMITED_TOSTRING
+inline grpc::string to_string(const int x) {
+  return std::to_string(static_cast<const long long int>(x));
+}
+inline grpc::string to_string(const unsigned int x) {
+  return std::to_string(static_cast<const long long unsigned int>(x));
+}
+#else
+using std::to_string;
+#endif
+
 }  // namespace grpc
 
 #endif  // GRPCXX_IMPL_CODEGEN_CONFIG_H
diff --git a/test/cpp/end2end/async_end2end_test.cc b/test/cpp/end2end/async_end2end_test.cc
index 535d8d5d3d..2e0c9da107 100644
--- a/test/cpp/end2end/async_end2end_test.cc
+++ b/test/cpp/end2end/async_end2end_test.cc
@@ -938,7 +938,7 @@ class AsyncEnd2endServerTryCancelTest : public AsyncEnd2endTest {
 
     // Client sends 3 messages (tags 3, 4 and 5)
     for (int tag_idx = 3; tag_idx <= 5; tag_idx++) {
-      send_request.set_message("Ping " + std::to_string(tag_idx));
+      send_request.set_message("Ping " + grpc::to_string(tag_idx));
       cli_stream->Write(send_request, tag(tag_idx));
       Verifier(GetParam().disable_blocking)
           .Expect(tag_idx, true)
@@ -1104,7 +1104,7 @@ class AsyncEnd2endServerTryCancelTest : public AsyncEnd2endTest {
     // Server sends three messages (tags 3, 4 and 5)
     // But if want_done tag is true, we might also see tag 11
     for (int tag_idx = 3; tag_idx <= 5; tag_idx++) {
-      send_response.set_message("Pong " + std::to_string(tag_idx));
+      send_response.set_message("Pong " + grpc::to_string(tag_idx));
       srv_stream.Write(send_response, tag(tag_idx));
       // Note that we'll add something to the verifier and verify that
       // something was seen, but it might be tag 11 and not what we
diff --git a/test/cpp/end2end/end2end_test.cc b/test/cpp/end2end/end2end_test.cc
index f52aa52f39..81318866c9 100644
--- a/test/cpp/end2end/end2end_test.cc
+++ b/test/cpp/end2end/end2end_test.cc
@@ -329,7 +329,7 @@ class End2endServerTryCancelTest : public End2endTest {
 
     // Send server_try_cancel value in the client metadata
     context.AddMetadata(kServerTryCancelRequest,
-                        std::to_string(server_try_cancel));
+                        grpc::to_string(server_try_cancel));
 
     auto stream = stub_->RequestStream(&context, &response);
 
@@ -402,7 +402,7 @@ class End2endServerTryCancelTest : public End2endTest {
 
     // Send server_try_cancel in the client metadata
     context.AddMetadata(kServerTryCancelRequest,
-                        std::to_string(server_try_cancel));
+                        grpc::to_string(server_try_cancel));
 
     request.set_message("hello");
     auto stream = stub_->ResponseStream(&context, request);
@@ -413,7 +413,7 @@ class End2endServerTryCancelTest : public End2endTest {
         break;
       }
       EXPECT_EQ(response.message(),
-                request.message() + std::to_string(num_msgs_read));
+                request.message() + grpc::to_string(num_msgs_read));
       num_msgs_read++;
     }
     gpr_log(GPR_INFO, "Read %d messages", num_msgs_read);
@@ -479,14 +479,14 @@ class End2endServerTryCancelTest : public End2endTest {
 
     // Send server_try_cancel in the client metadata
     context.AddMetadata(kServerTryCancelRequest,
-                        std::to_string(server_try_cancel));
+                        grpc::to_string(server_try_cancel));
 
     auto stream = stub_->BidiStream(&context);
 
     int num_msgs_read = 0;
     int num_msgs_sent = 0;
     while (num_msgs_sent < num_messages) {
-      request.set_message("hello " + std::to_string(num_msgs_sent));
+      request.set_message("hello " + grpc::to_string(num_msgs_sent));
       if (!stream->Write(request)) {
         break;
       }
@@ -548,7 +548,7 @@ TEST_P(End2endServerTryCancelTest, RequestEchoServerCancel) {
   ClientContext context;
 
   context.AddMetadata(kServerTryCancelRequest,
-                      std::to_string(CANCEL_BEFORE_PROCESSING));
+                      grpc::to_string(CANCEL_BEFORE_PROCESSING));
   Status s = stub_->Echo(&context, request, &response);
   EXPECT_FALSE(s.ok());
   EXPECT_EQ(grpc::StatusCode::CANCELLED, s.error_code());
diff --git a/test/cpp/end2end/test_service_impl.cc b/test/cpp/end2end/test_service_impl.cc
index cbaee92228..52abd80d69 100644
--- a/test/cpp/end2end/test_service_impl.cc
+++ b/test/cpp/end2end/test_service_impl.cc
@@ -33,6 +33,7 @@
 
 #include "test/cpp/end2end/test_service_impl.h"
 
+#include <string>
 #include <thread>
 
 #include <grpc++/security/credentials.h>
@@ -253,7 +254,7 @@ Status TestServiceImpl::ResponseStream(ServerContext* context,
   }
 
   for (int i = 0; i < kNumResponseStreamsMsgs; i++) {
-    response.set_message(request->message() + std::to_string(i));
+    response.set_message(request->message() + grpc::to_string(i));
     writer->Write(response);
   }
 
diff --git a/test/cpp/end2end/thread_stress_test.cc b/test/cpp/end2end/thread_stress_test.cc
index 94541f9a45..1e73f88917 100644
--- a/test/cpp/end2end/thread_stress_test.cc
+++ b/test/cpp/end2end/thread_stress_test.cc
@@ -230,7 +230,7 @@ class CommonStressTestSyncServer : public CommonStressTest<TestServiceImpl> {
 };
 
 class CommonStressTestAsyncServer
-    : public CommonStressTest<::grpc::testing::EchoTestService::AsyncService> {
+    : public CommonStressTest< ::grpc::testing::EchoTestService::AsyncService> {
  public:
   void SetUp() GRPC_OVERRIDE {
     shutting_down_ = false;
@@ -394,7 +394,7 @@ class AsyncClientEnd2endTest : public ::testing::Test {
     for (int i = 0; i < num_rpcs; ++i) {
       AsyncClientCall* call = new AsyncClientCall;
       EchoRequest request;
-      request.set_message("Hello: " + std::to_string(i));
+      request.set_message("Hello: " + grpc::to_string(i));
       call->response_reader =
           common_.GetStub()->AsyncEcho(&call->context, request, &cq_);
       call->response_reader->Finish(&call->response, &call->status,
diff --git a/test/cpp/util/metrics_server.cc b/test/cpp/util/metrics_server.cc
index cc6b39b753..1c7cd6382a 100644
--- a/test/cpp/util/metrics_server.cc
+++ b/test/cpp/util/metrics_server.cc
@@ -99,7 +99,7 @@ std::shared_ptr<QpsGauge> MetricsServiceImpl::CreateQpsGauge(
   std::lock_guard<std::mutex> lock(mu_);
 
   std::shared_ptr<QpsGauge> qps_gauge(new QpsGauge());
-  const auto p = qps_gauges_.emplace(name, qps_gauge);
+  const auto p = qps_gauges_.insert(std::make_pair(name, qps_gauge));
 
   // p.first is an iterator pointing to <name, shared_ptr<QpsGauge>> pair.
   // p.second is a boolean which is set to 'true' if the QpsGauge is
@@ -114,7 +114,7 @@ std::shared_ptr<QpsGauge> MetricsServiceImpl::CreateQpsGauge(
 std::unique_ptr<grpc::Server> MetricsServiceImpl::StartServer(int port) {
   gpr_log(GPR_INFO, "Building metrics server..");
 
-  const grpc::string address = "0.0.0.0:" + std::to_string(port);
+  const grpc::string address = "0.0.0.0:" + grpc::to_string(port);
 
   ServerBuilder builder;
   builder.AddListeningPort(address, grpc::InsecureServerCredentials());
diff --git a/test/cpp/util/test_credentials_provider.cc b/test/cpp/util/test_credentials_provider.cc
index 9d762ce657..6e68f59e6a 100644
--- a/test/cpp/util/test_credentials_provider.cc
+++ b/test/cpp/util/test_credentials_provider.cc
@@ -41,15 +41,9 @@
 
 #include "test/core/end2end/data/ssl_test_data.h"
 
+namespace grpc {
 namespace {
 
-using grpc::ChannelArguments;
-using grpc::ChannelCredentials;
-using grpc::InsecureChannelCredentials;
-using grpc::InsecureServerCredentials;
-using grpc::ServerCredentials;
-using grpc::SslCredentialsOptions;
-using grpc::SslServerCredentialsOptions;
 using grpc::testing::CredentialTypeProvider;
 
 // Provide test credentials. Thread-safe.
@@ -162,7 +156,6 @@ CredentialsProvider* GetProvider() {
 
 }  // namespace
 
-namespace grpc {
 namespace testing {
 
 void AddSecureType(const grpc::string& type,
-- 
GitLab