From 05c39aa45cf1cc89f16c5566d87da9dc79ba838c Mon Sep 17 00:00:00 2001
From: Botond Baranyi <botond.baranyi@ericsson.com>
Date: Tue, 20 Oct 2020 18:42:40 +0200
Subject: [PATCH] Fixed compilation with C++17 (bug 568000)

Signed-off-by: Botond Baranyi <botond.baranyi@ericsson.com>
Change-Id: I9b3dfddca22af980b1c6f17a1d205854d0ae098f
---
 common/dbgnew.hh                     |  7 ++++++-
 common/new.cc                        | 25 +++++++++++++++++++------
 compiler2/ProjectGenHelper.cc        |  2 +-
 core/BER.hh                          |  4 ++--
 core/RAW.cc                          |  6 +++---
 core/Universal_charstring.cc         |  6 +++---
 loggerplugins/TSTLogger/TSTLogger.cc | 20 ++++++++++----------
 7 files changed, 44 insertions(+), 26 deletions(-)

diff --git a/common/dbgnew.hh b/common/dbgnew.hh
index 7721aa578..14e04a893 100644
--- a/common/dbgnew.hh
+++ b/common/dbgnew.hh
@@ -42,13 +42,18 @@ static debug_new_counter_t debug_new_counter;
 void* operator new(size_t size, const char* file, int line);
 void* operator new[](size_t size, const char* file, int line);
 
-// TODO: these might be GCC version dependant
+// TODO: these might be GCC version dependent
 void* operator new(size_t size, const std::nothrow_t&, const char* file, int line);
 void* operator new[](size_t size, const std::nothrow_t&, const char* file, int line);
 
 inline void* operator new(size_t, void* __p, const char*, int) { return __p; }
 inline void* operator new[](size_t, void* __p, const char*, int) { return __p; }
 
+#if __cplusplus >= 201703L
+void* operator new(size_t size, std::align_val_t, const char* file, int line);
+void* operator new[](size_t size, std::align_val_t, const char* file, int line);
+#endif // C++11
+
 // Redirect "normal" new to memory-tracking placement new.
 #define new(...) new(__VA_ARGS__, __FILE__, __LINE__)
 
diff --git a/common/new.cc b/common/new.cc
index d9552aeea..a20d2cc7e 100644
--- a/common/new.cc
+++ b/common/new.cc
@@ -18,33 +18,33 @@
 
 static void *dummy = NULL;
 
-void *operator new(size_t size) throw (std::bad_alloc)
+void *operator new(size_t size)
 {
     return Malloc(size);
 }
 
-void *operator new[](size_t size) throw (std::bad_alloc)
+void *operator new[](size_t size)
 {
     if (size == 0) return &dummy;
     else return Malloc(size);
 }
 
-void operator delete(void *ptr) throw()
+void operator delete(void *ptr)
 {
     Free(ptr);
 }
 
-void operator delete(void *ptr, std::size_t) throw()
+void operator delete(void *ptr, std::size_t)
 {
     Free(ptr);
 }
 
-void operator delete[](void *ptr) throw()
+void operator delete[](void *ptr)
 {
     if (ptr != static_cast<void*>(&dummy)) Free(ptr);
 }
 
-void operator delete[](void *ptr, std::size_t) throw()
+void operator delete[](void *ptr, std::size_t)
 {
     if (ptr != static_cast<void*>(&dummy)) Free(ptr);
 }
@@ -76,6 +76,19 @@ void* operator new[](size_t size, const std::nothrow_t&, const char* file, int l
     else return Malloc_dbg(file, line, size);
 }
 
+#if __cplusplus >= 201703L
+void* operator new(size_t size, std::align_val_t, const char* file, int line)
+{
+    return Malloc_dbg(file, line, size);
+}
+
+void* operator new[](size_t size, std::align_val_t, const char* file, int line)
+{
+    if (size == 0) return &dummy;
+    else return Malloc_dbg(file, line, size);
+}
+#endif // C++11
+
 int debug_new_counter_t::count = 0; // initial value
 
 #if defined(__CYGWIN__) || defined(INTERIX)
diff --git a/compiler2/ProjectGenHelper.cc b/compiler2/ProjectGenHelper.cc
index 6a27db55a..278e2305c 100644
--- a/compiler2/ProjectGenHelper.cc
+++ b/compiler2/ProjectGenHelper.cc
@@ -491,7 +491,7 @@ size_t ProjectGenHelper::numOfLibs() const
 
 struct CompareStr
 {
-  bool operator () (const char* lhs, const char* rhs) {
+  bool operator () (const char* lhs, const char* rhs) const {
     int ret = strcmp(lhs, rhs);
     return (0 > ret);
   }
diff --git a/core/BER.hh b/core/BER.hh
index e8236325f..84af4caca 100644
--- a/core/BER.hh
+++ b/core/BER.hh
@@ -140,8 +140,8 @@ template<typename T>
 size_t min_needed_bits(T p)
 {
   if(p==0) return 1;
-  register size_t n=0;
-  register T tmp=p;
+  size_t n=0;
+  T tmp=p;
   while(tmp!=0) n++, tmp/=2;
   return n;
 }
diff --git a/core/RAW.cc b/core/RAW.cc
index 004c3298d..860d78d81 100644
--- a/core/RAW.cc
+++ b/core/RAW.cc
@@ -382,8 +382,8 @@ RAW_enc_tree* RAW_enc_tree::get_node(RAW_enc_tr_pos &req_pos)
  */
 int min_bits(int a)
 {
-  register int bits = 0;
-  register int tmp = a;
+  int bits = 0;
+  int tmp = a;
   if (a < 0) {
     bits = 1;
     tmp = -a;
@@ -398,7 +398,7 @@ int min_bits(int a)
 int min_bits(BIGNUM *a)
 {
   if (!a) return 0;
-  register int bits = BN_num_bits(a) + BN_is_negative(a);
+  int bits = BN_num_bits(a) + BN_is_negative(a);
   return bits;
 }
 
diff --git a/core/Universal_charstring.cc b/core/Universal_charstring.cc
index b34930b05..7b94b06ea 100644
--- a/core/Universal_charstring.cc
+++ b/core/Universal_charstring.cc
@@ -2016,7 +2016,7 @@ int UNIVERSAL_CHARSTRING::XER_encode(const XERdescriptor_t& p_td,
  */
 inline
 static unsigned int
-hash (register const char *str, register unsigned int len)
+hash (const char *str, unsigned int len)
 {
   static unsigned char asso_values[] =
     {
@@ -2122,11 +2122,11 @@ in_word_set (const char *str, unsigned int len)
 
   if (len <= MAX_WORD_LENGTH && len >= MIN_WORD_LENGTH)
     {
-      register int key = hash (str, len);
+      int key = hash (str, len);
 
       if (key <= MAX_HASH_VALUE && key >= 0)
         {
-          register const char s = wordlist[key];
+          const char s = wordlist[key];
           return s;
         }
     }
diff --git a/loggerplugins/TSTLogger/TSTLogger.cc b/loggerplugins/TSTLogger/TSTLogger.cc
index 074ee899d..1dee46007 100644
--- a/loggerplugins/TSTLogger/TSTLogger.cc
+++ b/loggerplugins/TSTLogger/TSTLogger.cc
@@ -76,19 +76,19 @@ class TCPClient
 public:
   TCPClient(): socket_fd(-1), timeout_time(30) {}
   // opens connection and returns socket file descriptor, throws exception on error
-  void open_connection(const string host_name, const string service_name) throw(SocketException);
+  void open_connection(const string host_name, const string service_name);
   // send a string to a socket, don't return until the whole string is sent
-  void send_string(const string& str) throw(SocketException);
+  void send_string(const string& str);
   // receive available data to the end of the parameter string, blocks until at least wait_for_bytes chars have arrived,
   // returns false if connection was closed
-  bool receive_string(string& str, const size_t wait_for_bytes) throw(SocketException);
+  bool receive_string(string& str, const size_t wait_for_bytes);
   // close connection
-  void close_connection() throw(SocketException);
+  void close_connection();
   time_t get_timeout() const { return timeout_time; }
   void set_timeout(time_t t) { timeout_time = t; }
 };
 
-void TCPClient::open_connection(const string host_name, const string service_name) throw(SocketException)
+void TCPClient::open_connection(const string host_name, const string service_name)
 {
   if (socket_fd!=-1) {
     close_connection();
@@ -116,7 +116,7 @@ void TCPClient::open_connection(const string host_name, const string service_nam
   }
 }
 
-void TCPClient::close_connection() throw(SocketException)
+void TCPClient::close_connection()
 {
   if (socket_fd==-1) {
     return;
@@ -157,7 +157,7 @@ wait_reset:
   }
 }
 
-void TCPClient::send_string(const string& str) throw(SocketException)
+void TCPClient::send_string(const string& str)
 {
   if (socket_fd==-1) {
     throw SocketException("Connection is not open");
@@ -177,7 +177,7 @@ void TCPClient::send_string(const string& str) throw(SocketException)
 
 // wait_for_bytes - wait until at least so many bytes arrived or timeout or connection closed,
 //                  if zero then wait until connection is closed
-bool TCPClient::receive_string(string& str, const size_t wait_for_bytes) throw(SocketException)
+bool TCPClient::receive_string(string& str, const size_t wait_for_bytes)
 {
   if (socket_fd==-1) {
     throw SocketException("Connection is not open");
@@ -220,7 +220,7 @@ class HTTPClient : public TCPClient
 public:
   HTTPClient(): TCPClient() {}
   string url_encode(const string& str);
-  string post_request(const string& host, const string& uri, const string& user_agent, const string_map& req_params) throw(SocketException);
+  string post_request(const string& host, const string& uri, const string& user_agent, const string_map& req_params);
 };
 
 string HTTPClient::url_encode(const string& str)
@@ -240,7 +240,7 @@ string HTTPClient::url_encode(const string& str)
   return ss.str();
 }
 
-string HTTPClient::post_request(const string& host, const string& uri, const string& user_agent, const string_map& req_params) throw(SocketException)
+string HTTPClient::post_request(const string& host, const string& uri, const string& user_agent, const string_map& req_params)
 {
   // compose request message
   stringstream req_ss;
-- 
GitLab