From 860c270c73048b4930ac8cbebcd60be746eb9782 Mon Sep 17 00:00:00 2001 From: Charles Pigott Date: Sun, 27 Dec 2020 10:44:22 +0000 Subject: Codechange: Replace assert_compile macro with static_assert --- src/network/core/os_abstraction.h | 4 ++-- src/network/core/tcp_admin.cpp | 8 ++++---- src/network/network.cpp | 10 +++++----- src/network/network_admin.cpp | 4 ++-- src/network/network_chat_gui.cpp | 2 +- src/network/network_client.cpp | 4 ++-- src/network/network_server.cpp | 10 +++++----- 7 files changed, 21 insertions(+), 21 deletions(-) (limited to 'src/network') diff --git a/src/network/core/os_abstraction.h b/src/network/core/os_abstraction.h index 8aa072aef..836cfeae8 100644 --- a/src/network/core/os_abstraction.h +++ b/src/network/core/os_abstraction.h @@ -210,7 +210,7 @@ static inline bool SetNoDelay(SOCKET d) } /* Make sure these structures have the size we expect them to be */ -assert_compile(sizeof(in_addr) == 4); ///< IPv4 addresses should be 4 bytes. -assert_compile(sizeof(in6_addr) == 16); ///< IPv6 addresses should be 16 bytes. +static_assert(sizeof(in_addr) == 4); ///< IPv4 addresses should be 4 bytes. +static_assert(sizeof(in6_addr) == 16); ///< IPv6 addresses should be 16 bytes. #endif /* NETWORK_CORE_OS_ABSTRACTION_H */ diff --git a/src/network/core/tcp_admin.cpp b/src/network/core/tcp_admin.cpp index 98227e019..c72583f55 100644 --- a/src/network/core/tcp_admin.cpp +++ b/src/network/core/tcp_admin.cpp @@ -18,10 +18,10 @@ #include "../../safeguards.h" /* Make sure that these enums match. */ -assert_compile((int)CRR_MANUAL == (int)ADMIN_CRR_MANUAL); -assert_compile((int)CRR_AUTOCLEAN == (int)ADMIN_CRR_AUTOCLEAN); -assert_compile((int)CRR_BANKRUPT == (int)ADMIN_CRR_BANKRUPT); -assert_compile((int)CRR_END == (int)ADMIN_CRR_END); +static_assert((int)CRR_MANUAL == (int)ADMIN_CRR_MANUAL); +static_assert((int)CRR_AUTOCLEAN == (int)ADMIN_CRR_AUTOCLEAN); +static_assert((int)CRR_BANKRUPT == (int)ADMIN_CRR_BANKRUPT); +static_assert((int)CRR_END == (int)ADMIN_CRR_END); /** * Create the admin handler for the given socket. diff --git a/src/network/network.cpp b/src/network/network.cpp index da341f253..907f15842 100644 --- a/src/network/network.cpp +++ b/src/network/network.cpp @@ -43,7 +43,7 @@ bool _ddc_fastforward = true; #endif /* DEBUG_DUMP_COMMANDS */ /** Make sure both pools have the same size. */ -assert_compile(NetworkClientInfoPool::MAX_SIZE == NetworkClientSocketPool::MAX_SIZE); +static_assert(NetworkClientInfoPool::MAX_SIZE == NetworkClientSocketPool::MAX_SIZE); /** The pool with client information. */ NetworkClientInfoPool _networkclientinfo_pool("NetworkClientInfo"); @@ -80,8 +80,8 @@ uint8 _network_advertise_retries; ///< The number of advertisement retries w CompanyMask _network_company_passworded; ///< Bitmask of the password status of all companies. /* Check whether NETWORK_NUM_LANDSCAPES is still in sync with NUM_LANDSCAPE */ -assert_compile((int)NETWORK_NUM_LANDSCAPES == (int)NUM_LANDSCAPE); -assert_compile((int)NETWORK_COMPANY_NAME_LENGTH == MAX_LENGTH_COMPANY_NAME_CHARS * MAX_CHAR_LENGTH); +static_assert((int)NETWORK_NUM_LANDSCAPES == (int)NUM_LANDSCAPE); +static_assert((int)NETWORK_COMPANY_NAME_LENGTH == MAX_LENGTH_COMPANY_NAME_CHARS * MAX_CHAR_LENGTH); extern NetworkUDPSocketHandler *_udp_client_socket; ///< udp client socket extern NetworkUDPSocketHandler *_udp_server_socket; ///< udp server socket @@ -322,7 +322,7 @@ StringID GetNetworkErrorMsg(NetworkErrorCode err) STR_NETWORK_ERROR_CLIENT_TIMEOUT_MAP, STR_NETWORK_ERROR_CLIENT_TIMEOUT_JOIN, }; - assert_compile(lengthof(network_error_strings) == NETWORK_ERROR_END); + static_assert(lengthof(network_error_strings) == NETWORK_ERROR_END); if (err >= (ptrdiff_t)lengthof(network_error_strings)) err = NETWORK_ERROR_GENERAL; @@ -920,7 +920,7 @@ void NetworkGameLoop() if (*p == ' ') p++; cp = CallocT(1); int company; - assert_compile(sizeof(cp->text) == 128); + static_assert(sizeof(cp->text) == 128); int ret = sscanf(p, "%x; %x; %x; %x; %x; %x; %x; \"%127[^\"]\"", &next_date, &next_date_fract, &company, &cp->tile, &cp->p1, &cp->p2, &cp->cmd, cp->text); /* There are 8 pieces of data to read, however the last is a * string that might or might not exist. Ignore it if that diff --git a/src/network/network_admin.cpp b/src/network/network_admin.cpp index f304740a6..007722ec6 100644 --- a/src/network/network_admin.cpp +++ b/src/network/network_admin.cpp @@ -54,7 +54,7 @@ static const AdminUpdateFrequency _admin_update_type_frequencies[] = { ADMIN_FREQUENCY_AUTOMATIC, ///< ADMIN_UPDATE_GAMESCRIPT }; /** Sanity check. */ -assert_compile(lengthof(_admin_update_type_frequencies) == ADMIN_UPDATE_END); +static_assert(lengthof(_admin_update_type_frequencies) == ADMIN_UPDATE_END); /** * Create a new socket for the server side of the admin network. @@ -86,7 +86,7 @@ ServerNetworkAdminSocketHandler::~ServerNetworkAdminSocketHandler() bool accept = !StrEmpty(_settings_client.network.admin_password) && _network_admins_connected < MAX_ADMINS; /* We can't go over the MAX_ADMINS limit here. However, if we accept * the connection, there has to be space in the pool. */ - assert_compile(NetworkAdminSocketPool::MAX_SIZE == MAX_ADMINS); + static_assert(NetworkAdminSocketPool::MAX_SIZE == MAX_ADMINS); assert(!accept || ServerNetworkAdminSocketHandler::CanAllocateItem()); return accept; } diff --git a/src/network/network_chat_gui.cpp b/src/network/network_chat_gui.cpp index 07348c048..e0f3bf57c 100644 --- a/src/network/network_chat_gui.cpp +++ b/src/network/network_chat_gui.cpp @@ -31,7 +31,7 @@ /** The draw buffer must be able to contain the chat message, client name and the "[All]" message, * some spaces and possible translations of [All] to other languages. */ -assert_compile((int)DRAW_STRING_BUFFER >= (int)NETWORK_CHAT_LENGTH + NETWORK_NAME_LENGTH + 40); +static_assert((int)DRAW_STRING_BUFFER >= (int)NETWORK_CHAT_LENGTH + NETWORK_NAME_LENGTH + 40); /** Spacing between chat lines. */ static const uint NETWORK_CHAT_LINE_SPACING = 3; diff --git a/src/network/network_client.cpp b/src/network/network_client.cpp index dc593eacd..eb5c4cbb3 100644 --- a/src/network/network_client.cpp +++ b/src/network/network_client.cpp @@ -324,7 +324,7 @@ const char *_network_join_server_password = nullptr; const char *_network_join_company_password = nullptr; /** Make sure the server ID length is the same as a md5 hash. */ -assert_compile(NETWORK_SERVER_ID_LENGTH == 16 * 2 + 1); +static_assert(NETWORK_SERVER_ID_LENGTH == 16 * 2 + 1); /*********** * Sending functions @@ -682,7 +682,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_ERROR(Packet *p STR_NETWORK_ERROR_TIMEOUT_MAP, // NETWORK_ERROR_TIMEOUT_MAP STR_NETWORK_ERROR_TIMEOUT_JOIN, // NETWORK_ERROR_TIMEOUT_JOIN }; - assert_compile(lengthof(network_error_strings) == NETWORK_ERROR_END); + static_assert(lengthof(network_error_strings) == NETWORK_ERROR_END); NetworkErrorCode error = (NetworkErrorCode)p->Recv_uint8(); diff --git a/src/network/network_server.cpp b/src/network/network_server.cpp index c82c51cfd..1454991a8 100644 --- a/src/network/network_server.cpp +++ b/src/network/network_server.cpp @@ -41,9 +41,9 @@ DECLARE_POSTFIX_INCREMENT(ClientID) static ClientID _network_client_id = CLIENT_ID_FIRST; /** Make very sure the preconditions given in network_type.h are actually followed */ -assert_compile(MAX_CLIENT_SLOTS > MAX_CLIENTS); +static_assert(MAX_CLIENT_SLOTS > MAX_CLIENTS); /** Yes... */ -assert_compile(NetworkClientSocketPool::MAX_SIZE == MAX_CLIENT_SLOTS); +static_assert(NetworkClientSocketPool::MAX_SIZE == MAX_CLIENT_SLOTS); /** The pool with clients. */ NetworkClientSocketPool _networkclientsocket_pool("NetworkClientSocket"); @@ -223,7 +223,7 @@ ServerNetworkGameSocketHandler::ServerNetworkGameSocketHandler(SOCKET s) : Netwo /* The Socket and Info pools need to be the same in size. After all, * each Socket will be associated with at most one Info object. As * such if the Socket was allocated the Info object can as well. */ - assert_compile(NetworkClientSocketPool::MAX_SIZE == NetworkClientInfoPool::MAX_SIZE); + static_assert(NetworkClientSocketPool::MAX_SIZE == NetworkClientInfoPool::MAX_SIZE); } /** @@ -311,7 +311,7 @@ NetworkRecvStatus ServerNetworkGameSocketHandler::CloseConnection(NetworkRecvSta /* We can't go over the MAX_CLIENTS limit here. However, the * pool must have place for all clients and ourself. */ - assert_compile(NetworkClientSocketPool::MAX_SIZE == MAX_CLIENTS + 1); + static_assert(NetworkClientSocketPool::MAX_SIZE == MAX_CLIENTS + 1); assert(!accept || ServerNetworkGameSocketHandler::CanAllocateItem()); return accept; } @@ -1962,7 +1962,7 @@ void NetworkServerShowStatusToConsole() "ready", "active" }; - assert_compile(lengthof(stat_str) == NetworkClientSocket::STATUS_END); + static_assert(lengthof(stat_str) == NetworkClientSocket::STATUS_END); for (NetworkClientSocket *cs : NetworkClientSocket::Iterate()) { NetworkClientInfo *ci = cs->GetInfo(); -- cgit v1.2.3-54-g00ecf