THRIFT-4762: Applied some C++11 refactorings to the runtime library and compiler (#1719)

* make use of C++11 override keyword
* added const specifier to TTransport::getOrigin()
* added more const correctness to the compiler
* make use of auto keyword
* replaced usage of NULL with nullptr
* make use of explicitly-defaulted function definition
* extended changelog
diff --git a/lib/cpp/test/processor/EventLog.cpp b/lib/cpp/test/processor/EventLog.cpp
index e3ddbcc..c8e0d9b 100644
--- a/lib/cpp/test/processor/EventLog.cpp
+++ b/lib/cpp/test/processor/EventLog.cpp
@@ -110,7 +110,7 @@
 Event EventLog::waitForConnEvent(uint32_t connId, int64_t timeout) {
   Synchronized s(monitor_);
 
-  EventList::iterator it = events_.begin();
+  auto it = events_.begin();
   while (true) {
     try {
       // TODO: it would be nicer to honor timeout for the duration of this
diff --git a/lib/cpp/test/processor/Handlers.h b/lib/cpp/test/processor/Handlers.h
index 29784d8..05d19ed 100644
--- a/lib/cpp/test/processor/Handlers.h
+++ b/lib/cpp/test/processor/Handlers.h
@@ -32,31 +32,31 @@
   ParentHandler(const std::shared_ptr<EventLog>& log)
     : triggerMonitor(&mutex_), generation_(0), wait_(false), log_(log) {}
 
-  int32_t incrementGeneration() {
+  int32_t incrementGeneration() override {
     concurrency::Guard g(mutex_);
     log_->append(EventLog::ET_CALL_INCREMENT_GENERATION, 0, 0);
     return ++generation_;
   }
 
-  int32_t getGeneration() {
+  int32_t getGeneration() override {
     concurrency::Guard g(mutex_);
     log_->append(EventLog::ET_CALL_GET_GENERATION, 0, 0);
     return generation_;
   }
 
-  void addString(const std::string& s) {
+  void addString(const std::string& s) override {
     concurrency::Guard g(mutex_);
     log_->append(EventLog::ET_CALL_ADD_STRING, 0, 0);
     strings_.push_back(s);
   }
 
-  void getStrings(std::vector<std::string>& _return) {
+  void getStrings(std::vector<std::string>& _return) override {
     concurrency::Guard g(mutex_);
     log_->append(EventLog::ET_CALL_GET_STRINGS, 0, 0);
     _return = strings_;
   }
 
-  void getDataWait(std::string& _return, const int32_t length) {
+  void getDataWait(std::string& _return, const int32_t length) override {
     concurrency::Guard g(mutex_);
     log_->append(EventLog::ET_CALL_GET_DATA_WAIT, 0, 0);
 
@@ -65,14 +65,14 @@
     _return.append(length, 'a');
   }
 
-  void onewayWait() {
+  void onewayWait() override {
     concurrency::Guard g(mutex_);
     log_->append(EventLog::ET_CALL_ONEWAY_WAIT, 0, 0);
 
     blockUntilTriggered();
   }
 
-  void exceptionWait(const std::string& message) {
+  void exceptionWait(const std::string& message) override {
     concurrency::Guard g(mutex_);
     log_->append(EventLog::ET_CALL_EXCEPTION_WAIT, 0, 0);
 
@@ -83,7 +83,7 @@
     throw e;
   }
 
-  void unexpectedExceptionWait(const std::string& message) {
+  void unexpectedExceptionWait(const std::string& message) override {
     concurrency::Guard g(mutex_);
     log_->append(EventLog::ET_CALL_UNEXPECTED_EXCEPTION_WAIT, 0, 0);
 
@@ -148,7 +148,7 @@
 public:
   ChildHandler(const std::shared_ptr<EventLog>& log) : ParentHandler(log), value_(0) {}
 
-  int32_t setValue(const int32_t value) {
+  int32_t setValue(const int32_t value) override {
     concurrency::Guard g(mutex_);
     log_->append(EventLog::ET_CALL_SET_VALUE, 0, 0);
 
@@ -157,7 +157,7 @@
     return oldValue;
   }
 
-  int32_t getValue() {
+  int32_t getValue() override {
     concurrency::Guard g(mutex_);
     log_->append(EventLog::ET_CALL_GET_VALUE, 0, 0);
 
@@ -198,20 +198,20 @@
 public:
   ServerEventHandler(const std::shared_ptr<EventLog>& log) : nextId_(1), log_(log) {}
 
-  virtual void preServe() {}
+  void preServe() override {}
 
-  virtual void* createContext(std::shared_ptr<protocol::TProtocol> input,
-                              std::shared_ptr<protocol::TProtocol> output) {
+  void* createContext(std::shared_ptr<protocol::TProtocol> input,
+                              std::shared_ptr<protocol::TProtocol> output) override {
     ConnContext* context = new ConnContext(input, output, nextId_);
     ++nextId_;
     log_->append(EventLog::ET_CONN_CREATED, context->id, 0);
     return context;
   }
 
-  virtual void deleteContext(void* serverContext,
+  void deleteContext(void* serverContext,
                              std::shared_ptr<protocol::TProtocol> input,
-                             std::shared_ptr<protocol::TProtocol> output) {
-    ConnContext* context = reinterpret_cast<ConnContext*>(serverContext);
+                             std::shared_ptr<protocol::TProtocol> output) override {
+    auto* context = reinterpret_cast<ConnContext*>(serverContext);
 
     if (input != context->input) {
       abort();
@@ -225,8 +225,8 @@
     delete context;
   }
 
-  virtual void processContext(void* serverContext,
-                              std::shared_ptr<transport::TTransport> transport) {
+  void processContext(void* serverContext,
+                              std::shared_ptr<transport::TTransport> transport) override {
 // TODO: We currently don't test the behavior of the processContext()
 // calls.  The various server implementations call processContext() at
 // slightly different times, and it is too annoying to try and account for
@@ -258,8 +258,8 @@
 public:
   ProcessorEventHandler(const std::shared_ptr<EventLog>& log) : nextId_(1), log_(log) {}
 
-  void* getContext(const char* fnName, void* serverContext) {
-    ConnContext* connContext = reinterpret_cast<ConnContext*>(serverContext);
+  void* getContext(const char* fnName, void* serverContext) override {
+    auto* connContext = reinterpret_cast<ConnContext*>(serverContext);
 
     CallContext* context = new CallContext(connContext, nextId_, fnName);
     ++nextId_;
@@ -268,47 +268,47 @@
     return context;
   }
 
-  void freeContext(void* ctx, const char* fnName) {
-    CallContext* context = reinterpret_cast<CallContext*>(ctx);
+  void freeContext(void* ctx, const char* fnName) override {
+    auto* context = reinterpret_cast<CallContext*>(ctx);
     checkName(context, fnName);
     log_->append(EventLog::ET_CALL_FINISHED, context->connContext->id, context->id, fnName);
     delete context;
   }
 
-  void preRead(void* ctx, const char* fnName) {
-    CallContext* context = reinterpret_cast<CallContext*>(ctx);
+  void preRead(void* ctx, const char* fnName) override {
+    auto* context = reinterpret_cast<CallContext*>(ctx);
     checkName(context, fnName);
     log_->append(EventLog::ET_PRE_READ, context->connContext->id, context->id, fnName);
   }
 
-  void postRead(void* ctx, const char* fnName, uint32_t bytes) {
+  void postRead(void* ctx, const char* fnName, uint32_t bytes) override {
     THRIFT_UNUSED_VARIABLE(bytes);
-    CallContext* context = reinterpret_cast<CallContext*>(ctx);
+    auto* context = reinterpret_cast<CallContext*>(ctx);
     checkName(context, fnName);
     log_->append(EventLog::ET_POST_READ, context->connContext->id, context->id, fnName);
   }
 
-  void preWrite(void* ctx, const char* fnName) {
-    CallContext* context = reinterpret_cast<CallContext*>(ctx);
+  void preWrite(void* ctx, const char* fnName) override {
+    auto* context = reinterpret_cast<CallContext*>(ctx);
     checkName(context, fnName);
     log_->append(EventLog::ET_PRE_WRITE, context->connContext->id, context->id, fnName);
   }
 
-  void postWrite(void* ctx, const char* fnName, uint32_t bytes) {
+  void postWrite(void* ctx, const char* fnName, uint32_t bytes) override {
     THRIFT_UNUSED_VARIABLE(bytes);
-    CallContext* context = reinterpret_cast<CallContext*>(ctx);
+    auto* context = reinterpret_cast<CallContext*>(ctx);
     checkName(context, fnName);
     log_->append(EventLog::ET_POST_WRITE, context->connContext->id, context->id, fnName);
   }
 
-  void asyncComplete(void* ctx, const char* fnName) {
-    CallContext* context = reinterpret_cast<CallContext*>(ctx);
+  void asyncComplete(void* ctx, const char* fnName) override {
+    auto* context = reinterpret_cast<CallContext*>(ctx);
     checkName(context, fnName);
     log_->append(EventLog::ET_ASYNC_COMPLETE, context->connContext->id, context->id, fnName);
   }
 
-  void handlerError(void* ctx, const char* fnName) {
-    CallContext* context = reinterpret_cast<CallContext*>(ctx);
+  void handlerError(void* ctx, const char* fnName) override {
+    auto* context = reinterpret_cast<CallContext*>(ctx);
     checkName(context, fnName);
     log_->append(EventLog::ET_HANDLER_ERROR, context->connContext->id, context->id, fnName);
   }
diff --git a/lib/cpp/test/processor/ProcessorTest.cpp b/lib/cpp/test/processor/ProcessorTest.cpp
index 9483a0e..a36ef3e 100644
--- a/lib/cpp/test/processor/ProcessorTest.cpp
+++ b/lib/cpp/test/processor/ProcessorTest.cpp
@@ -116,9 +116,9 @@
     // TNonblockingServer automatically uses TFramedTransport.
     // Raise an exception if the supplied transport factory is not a
     // TFramedTransportFactory
-    TFramedTransportFactory* framedFactory
+    auto* framedFactory
         = dynamic_cast<TFramedTransportFactory*>(transportFactory.get());
-    if (framedFactory == NULL) {
+    if (framedFactory == nullptr) {
       throw TException("TNonblockingServer must use TFramedTransport");
     }
 
@@ -145,9 +145,9 @@
     // TNonblockingServer automatically uses TFramedTransport.
     // Raise an exception if the supplied transport factory is not a
     // TFramedTransportFactory
-    TFramedTransportFactory* framedFactory
+    auto* framedFactory
         = dynamic_cast<TFramedTransportFactory*>(transportFactory.get());
-    if (framedFactory == NULL) {
+    if (framedFactory == nullptr) {
       throw TException("TNonblockingServer must use TFramedTransport");
     }
 
@@ -244,14 +244,14 @@
     processor_->setEventHandler(processorEventHandler_);
   }
 
-  std::shared_ptr<TServer> createServer(uint16_t port) {
+  std::shared_ptr<TServer> createServer(uint16_t port) override {
     ServerTraits_ serverTraits;
     return serverTraits.createServer(processor_, port, transportFactory_, protocolFactory_);
   }
 
-  std::shared_ptr<TServerEventHandler> getServerEventHandler() { return serverEventHandler_; }
+  std::shared_ptr<TServerEventHandler> getServerEventHandler() override { return serverEventHandler_; }
 
-  void bindSuccessful(uint16_t port) { port_ = port; }
+  void bindSuccessful(uint16_t port) override { port_ = port; }
 
   uint16_t getPort() const { return port_; }
 
@@ -524,7 +524,7 @@
   // can test the timing for the preRead() call.
   string requestName = "getDataWait";
   string eventName = "ParentService.getDataWait";
-  int32_t seqid = int32_t(time(NULL));
+  auto seqid = int32_t(time(nullptr));
   TBinaryProtocol protocol(socket);
   protocol.writeMessageBegin(requestName, T_CALL, seqid);
   socket->flush();
diff --git a/lib/cpp/test/processor/ServerThread.h b/lib/cpp/test/processor/ServerThread.h
index 61e31a3..9cca2d6 100644
--- a/lib/cpp/test/processor/ServerThread.h
+++ b/lib/cpp/test/processor/ServerThread.h
@@ -35,7 +35,7 @@
  */
 class ServerState {
 public:
-  virtual ~ServerState() {}
+  virtual ~ServerState() = default;
 
   /**
    * Create a server to listen on the specified port.
@@ -105,9 +105,9 @@
   public:
     Helper(ServerThread* serverThread) : serverThread_(serverThread) {}
 
-    void run() { serverThread_->run(); }
+    void run() override { serverThread_->run(); }
 
-    void preServe() { serverThread_->preServe(); }
+    void preServe() override { serverThread_->preServe(); }
 
   private:
     ServerThread* serverThread_;