From 3667fb62e28a8659e9ca10d85f72b5aab0e7c75b Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Sun, 17 Jun 2012 03:10:59 -0400 Subject: [PATCH] Replace COMPILER_ASSERT with C++0B static_assert --- Sources/Plasma/Apps/plUruLauncher/Main.cpp | 2 +- Sources/Plasma/CoreLib/HeadSpin.h | 8 -------- Sources/Plasma/NucleusLib/pnAsyncCore/Private/pnAcIo.h | 2 +- .../pnAsyncCoreExe/Private/W9x/pnAceW9xSocket.cpp | 2 +- Sources/Plasma/NucleusLib/pnAsyncCoreExe/pnAceCore.cpp | 2 +- Sources/Plasma/NucleusLib/pnNetBase/pnNbError.cpp | 4 ++-- Sources/Plasma/NucleusLib/pnNetCli/pnNcEncrypt.cpp | 2 +- .../Private/Protocols/Cli2Auth/pnNpCli2Auth.h | 4 ++-- .../Private/Protocols/Cli2Game/pnNpCli2Game.h | 4 ++-- .../Private/Protocols/Cli2GateKeeper/pnNpCli2GateKeeper.h | 4 ++-- .../NucleusLib/pnNetProtocol/Private/pnNpCommon.cpp | 2 +- .../Plasma/NucleusLib/pnProduct/Private/pnPrBranchId.cpp | 2 +- .../Plasma/NucleusLib/pnProduct/Private/pnPrBuildId.cpp | 2 +- Sources/Plasma/NucleusLib/pnUtils/Win32/pnUtW32Path.cpp | 4 ++-- Sources/Plasma/NucleusLib/pnUtils/Win32/pnUtW32Uuid.cpp | 6 ++---- Sources/Plasma/NucleusLib/pnUtils/pnUtTime.cpp | 2 +- Sources/Plasma/PubUtilLib/plNetGameLib/Intern.h | 2 +- .../Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp | 2 +- 18 files changed, 23 insertions(+), 33 deletions(-) diff --git a/Sources/Plasma/Apps/plUruLauncher/Main.cpp b/Sources/Plasma/Apps/plUruLauncher/Main.cpp index 06b94ab5..2029d23e 100644 --- a/Sources/Plasma/Apps/plUruLauncher/Main.cpp +++ b/Sources/Plasma/Apps/plUruLauncher/Main.cpp @@ -208,7 +208,7 @@ static void LogV (ELogSev sev, const wchar_t fmt[], va_list args) { { stdout, L"Inf" }, { stderr, L"Err" }, }; - COMPILER_ASSERT(arrsize(s_log) == kNumLogSev); + static_assert(arrsize(s_log) == kNumLogSev, "Log severity array and enum have different sizes"); fwprintf (s_log[sev].file, L"%s: ", s_log[sev].pre); vfwprintf(s_log[sev].file, fmt, args); diff --git a/Sources/Plasma/CoreLib/HeadSpin.h b/Sources/Plasma/CoreLib/HeadSpin.h index b8347441..42a524f2 100644 --- a/Sources/Plasma/CoreLib/HeadSpin.h +++ b/Sources/Plasma/CoreLib/HeadSpin.h @@ -297,14 +297,6 @@ typedef hsColor32 hsRGBAColor32; # define NULL_STMT ((void)0) #endif - -//=========================================================================== -// Old COMPILER_ASSERT Macro -// This DEPRECATED. Use static_assert instead! -//=========================================================================== -#define COMPILER_ASSERT(expr) static_assert(expr, "old compiler assert failure") -#define COMPILER_ASSERT_HEADER(prefix,expr) static_assert(expr, "old compiler assert failure") - //=========================================================================== template inline T max (const T & a, const T & b) { diff --git a/Sources/Plasma/NucleusLib/pnAsyncCore/Private/pnAcIo.h b/Sources/Plasma/NucleusLib/pnAsyncCore/Private/pnAcIo.h index 4d22c11e..b2dae81d 100644 --- a/Sources/Plasma/NucleusLib/pnAsyncCore/Private/pnAcIo.h +++ b/Sources/Plasma/NucleusLib/pnAsyncCore/Private/pnAcIo.h @@ -171,7 +171,7 @@ enum EConnType { kNumConnTypes }; -COMPILER_ASSERT_HEADER(EConnType, kNumConnTypes < 256); +static_assert(kNumConnTypes <= 0xFF, "EConnType overflows uint8"); #define IS_TEXT_CONNTYPE(c) \ (((int)(c)) == kConnTypeAdminInterface) diff --git a/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/W9x/pnAceW9xSocket.cpp b/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/W9x/pnAceW9xSocket.cpp index c7d63d53..b693e0e1 100644 --- a/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/W9x/pnAceW9xSocket.cpp +++ b/Sources/Plasma/NucleusLib/pnAsyncCoreExe/Private/W9x/pnAceW9xSocket.cpp @@ -583,7 +583,7 @@ void CSocket::OnWriteReady () { &m_sendQueue[result], m_sendQueue.Bytes() - result ); - COMPILER_ASSERT(sizeof(m_sendQueue[0]) == sizeof(uint8_t)); + static_assert(sizeof(m_sendQueue[0]) == sizeof(uint8_t), "SendQueue array members are an unexpected size"); m_sendQueue.SetCount(m_sendQueue.Count() - result); } diff --git a/Sources/Plasma/NucleusLib/pnAsyncCoreExe/pnAceCore.cpp b/Sources/Plasma/NucleusLib/pnAsyncCoreExe/pnAceCore.cpp index 04ac913c..518e2411 100644 --- a/Sources/Plasma/NucleusLib/pnAsyncCoreExe/pnAceCore.cpp +++ b/Sources/Plasma/NucleusLib/pnAsyncCoreExe/pnAceCore.cpp @@ -235,7 +235,7 @@ void AsyncSleep (unsigned sleepMs) { //============================================================================ long AsyncPerfGetCounter (unsigned id) { - COMPILER_ASSERT(arrsize(s_perf) == kNumAsyncPerfCounters); + static_assert(arrsize(s_perf) == kNumAsyncPerfCounters, "Max async counters and array size do not match."); ASSERT(id < kNumAsyncPerfCounters); return s_perf[id]; } diff --git a/Sources/Plasma/NucleusLib/pnNetBase/pnNbError.cpp b/Sources/Plasma/NucleusLib/pnNetBase/pnNbError.cpp index b54431a4..a913b320 100644 --- a/Sources/Plasma/NucleusLib/pnNetBase/pnNbError.cpp +++ b/Sources/Plasma/NucleusLib/pnNetBase/pnNbError.cpp @@ -105,7 +105,7 @@ const wchar_t * NetErrorToString (ENetError code) { L"Server Busy", // kNetErrServerBusy L"Vault Node Access Violation", // kNetErrVaultNodeAccessViolation }; - COMPILER_ASSERT(arrsize(s_errors) == kNumNetErrors); + static_assert(arrsize(s_errors) == kNumNetErrors, "Number of Net Error descriptions and total Net Error count are not equal"); if ((unsigned)code >= arrsize(s_errors)) { if (code == kNetPending) @@ -172,7 +172,7 @@ const wchar_t * NetErrorAsString (ENetError code) { L"kNetErrServerBusy", L"kNetErrVaultNodeAccessViolation", }; - COMPILER_ASSERT(arrsize(s_errors) == kNumNetErrors); + static_assert(arrsize(s_errors) == kNumNetErrors, "Number of string-ized Net Errors and total Net Error count are not equal"); if ((unsigned)code >= arrsize(s_errors)) { if (code == kNetPending) diff --git a/Sources/Plasma/NucleusLib/pnNetCli/pnNcEncrypt.cpp b/Sources/Plasma/NucleusLib/pnNetCli/pnNcEncrypt.cpp index 95563877..594818f6 100644 --- a/Sources/Plasma/NucleusLib/pnNetCli/pnNcEncrypt.cpp +++ b/Sources/Plasma/NucleusLib/pnNetCli/pnNcEncrypt.cpp @@ -78,7 +78,7 @@ namespace pnNetCli { ***/ -COMPILER_ASSERT(IS_POW2(kNetDiffieHellmanKeyBits)); +static_assert(IS_POW2(kNetDiffieHellmanKeyBits), "DH Key bit count is not a power of 2"); /***************************************************************************** diff --git a/Sources/Plasma/NucleusLib/pnNetProtocol/Private/Protocols/Cli2Auth/pnNpCli2Auth.h b/Sources/Plasma/NucleusLib/pnNetProtocol/Private/Protocols/Cli2Auth/pnNpCli2Auth.h index 1b6a10b2..f7fc7024 100644 --- a/Sources/Plasma/NucleusLib/pnNetProtocol/Private/Protocols/Cli2Auth/pnNpCli2Auth.h +++ b/Sources/Plasma/NucleusLib/pnNetProtocol/Private/Protocols/Cli2Auth/pnNpCli2Auth.h @@ -133,7 +133,7 @@ enum { kNumCli2AuthMessages }; -COMPILER_ASSERT_HEADER(Cli2Auth, kNumCli2AuthMessages <= (uint16_t)-1); +static_assert(kNumCli2AuthMessages <= 0xFFFF, "Cli2Auth message types overflow uint16"); enum { // Global @@ -212,7 +212,7 @@ enum { kNumAuth2CliMessages }; -COMPILER_ASSERT_HEADER(Cli2Auth, kNumAuth2CliMessages <= (uint16_t)-1); +static_assert(kNumAuth2CliMessages <= 0xFFFF, "Auth2Cli message types overflow uint16"); //============================================================================ diff --git a/Sources/Plasma/NucleusLib/pnNetProtocol/Private/Protocols/Cli2Game/pnNpCli2Game.h b/Sources/Plasma/NucleusLib/pnNetProtocol/Private/Protocols/Cli2Game/pnNpCli2Game.h index f01b2798..ac06b83c 100644 --- a/Sources/Plasma/NucleusLib/pnNetProtocol/Private/Protocols/Cli2Game/pnNpCli2Game.h +++ b/Sources/Plasma/NucleusLib/pnNetProtocol/Private/Protocols/Cli2Game/pnNpCli2Game.h @@ -65,7 +65,7 @@ enum { kNumCli2GameMessages }; -COMPILER_ASSERT_HEADER(Cli2Game, kNumCli2GameMessages <= (uint16_t)-1); +static_assert(kNumCli2GameMessages <= 0xFFFF, "Cli2Game message types overflow uint16"); enum { // Global @@ -80,7 +80,7 @@ enum { kNumGame2CliMessages }; -COMPILER_ASSERT_HEADER(Cli2Game, kNumGame2CliMessages <= (uint16_t)-1); +static_assert(kNumGame2CliMessages <= 0xFFFF, "Game2Cli message types overflow uint16"); //============================================================================ diff --git a/Sources/Plasma/NucleusLib/pnNetProtocol/Private/Protocols/Cli2GateKeeper/pnNpCli2GateKeeper.h b/Sources/Plasma/NucleusLib/pnNetProtocol/Private/Protocols/Cli2GateKeeper/pnNpCli2GateKeeper.h index 7e04142f..42810676 100644 --- a/Sources/Plasma/NucleusLib/pnNetProtocol/Private/Protocols/Cli2GateKeeper/pnNpCli2GateKeeper.h +++ b/Sources/Plasma/NucleusLib/pnNetProtocol/Private/Protocols/Cli2GateKeeper/pnNpCli2GateKeeper.h @@ -62,7 +62,7 @@ enum { kNumCli2GateKeeperMessages }; -COMPILER_ASSERT_HEADER(Cli2GateKeeper, kNumCli2GateKeeperMessages <= (uint16_t)-1); +static_assert(kNumCli2GateKeeperMessages <= 0xFFFF, "Cli2GateKeeper message types overflow uint16"); enum { // Global @@ -72,7 +72,7 @@ enum { kNumGateKeeper2CliMessages }; -COMPILER_ASSERT_HEADER(Cli2GateKeeper, kNumGateKeeper2CliMessages <= (uint16_t)-1); +static_assert(kNumGateKeeper2CliMessages <= 0xFFFF, "GateKeeper2Cli message types overflow uint16"); //============================================================================ diff --git a/Sources/Plasma/NucleusLib/pnNetProtocol/Private/pnNpCommon.cpp b/Sources/Plasma/NucleusLib/pnNetProtocol/Private/pnNpCommon.cpp index 96d7c649..b82ee37d 100644 --- a/Sources/Plasma/NucleusLib/pnNetProtocol/Private/pnNpCommon.cpp +++ b/Sources/Plasma/NucleusLib/pnNetProtocol/Private/pnNpCommon.cpp @@ -53,7 +53,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com namespace pnNpCommon { // Verify our uint64_t constants were properly inited as such. -COMPILER_ASSERT(NetVaultNode::kBlob_2); +static_assert(NetVaultNode::kBlob_2, "NetVaultNode constants failed to init"); diff --git a/Sources/Plasma/NucleusLib/pnProduct/Private/pnPrBranchId.cpp b/Sources/Plasma/NucleusLib/pnProduct/Private/pnPrBranchId.cpp index 7a9ec72c..a4ff82d8 100644 --- a/Sources/Plasma/NucleusLib/pnProduct/Private/pnPrBranchId.cpp +++ b/Sources/Plasma/NucleusLib/pnProduct/Private/pnPrBranchId.cpp @@ -60,7 +60,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com // This value is manually changed upon each branch so that client applications // built from this branch may not connect to servers built from another. #define BRANCH_ID 1 -COMPILER_ASSERT(BRANCH_ID != 0); +static_assert(BRANCH_ID != 0, "BranchID cannot be 0"); #else diff --git a/Sources/Plasma/NucleusLib/pnProduct/Private/pnPrBuildId.cpp b/Sources/Plasma/NucleusLib/pnProduct/Private/pnPrBuildId.cpp index 698d1efb..9d650086 100644 --- a/Sources/Plasma/NucleusLib/pnProduct/Private/pnPrBuildId.cpp +++ b/Sources/Plasma/NucleusLib/pnProduct/Private/pnPrBuildId.cpp @@ -58,7 +58,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com // This line must NEVER be modified manually; it is automatically updated // by the build server. #define BUILD_ID 912 -COMPILER_ASSERT(BUILD_ID != 0); +static_assert(BUILD_ID != 0, "BuildID cannot be 0"); /***************************************************************************** diff --git a/Sources/Plasma/NucleusLib/pnUtils/Win32/pnUtW32Path.cpp b/Sources/Plasma/NucleusLib/pnUtils/Win32/pnUtW32Path.cpp index a7abfd00..2d142507 100644 --- a/Sources/Plasma/NucleusLib/pnUtils/Win32/pnUtW32Path.cpp +++ b/Sources/Plasma/NucleusLib/pnUtils/Win32/pnUtW32Path.cpp @@ -56,7 +56,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com ***/ // make sure our definition is at least as big as the compiler's definition -COMPILER_ASSERT(MAX_PATH >= _MAX_PATH); +static_assert(MAX_PATH >= _MAX_PATH, "Windows and STDlib MAX_PATH constants differ"); //=========================================================================== @@ -546,7 +546,7 @@ EPathCreateDirError PathCreateDirectory (const wchar_t path[], unsigned flags) { // if we successfully created the directory then we're done if (result) { // Avoid check for kPathCreateDirFlagOsError - COMPILER_ASSERT(kPathCreateDirSuccess == NO_ERROR); + static_assert(kPathCreateDirSuccess == NO_ERROR, "Path creation success and NO_ERROR constants differ"); return kPathCreateDirSuccess; } diff --git a/Sources/Plasma/NucleusLib/pnUtils/Win32/pnUtW32Uuid.cpp b/Sources/Plasma/NucleusLib/pnUtils/Win32/pnUtW32Uuid.cpp index 6c0b1c38..acd519d8 100644 --- a/Sources/Plasma/NucleusLib/pnUtils/Win32/pnUtW32Uuid.cpp +++ b/Sources/Plasma/NucleusLib/pnUtils/Win32/pnUtW32Uuid.cpp @@ -51,8 +51,6 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com #if 0 -COMPILER_ASSERT(sizeof(Uuid) >= sizeof(GUID)); - void Uuid::Clear() { UuidCreateNil( (GUID *)this ); @@ -120,7 +118,7 @@ Uuid Uuid::Generate() * ***/ -COMPILER_ASSERT(sizeof(Uuid) >= sizeof(GUID)); +static_assert(sizeof(Uuid) >= sizeof(GUID), "pnUtils Uuid and Win32 GUID types differ in size"); //============================================================================ Uuid GuidGenerate () { @@ -137,7 +135,7 @@ void GuidClear (Uuid * uuid) { //============================================================================ bool GuidFromString (const wchar_t str[], Uuid * uuid) { ASSERT(uuid); - COMPILER_ASSERT(sizeof(wchar_t) == sizeof(unsigned short)); + static_assert(sizeof(wchar_t) == sizeof(unsigned short), "Wchar is not an uint16"); return RPC_S_OK == UuidFromStringW((unsigned short *) str, (GUID *) uuid); } diff --git a/Sources/Plasma/NucleusLib/pnUtils/pnUtTime.cpp b/Sources/Plasma/NucleusLib/pnUtils/pnUtTime.cpp index 31e83eb0..9735b04a 100644 --- a/Sources/Plasma/NucleusLib/pnUtils/pnUtTime.cpp +++ b/Sources/Plasma/NucleusLib/pnUtils/pnUtTime.cpp @@ -118,7 +118,7 @@ uint32_t TimeGetSecondsSince2001Utc () { uint64_t TimeGetTime () { #ifdef HS_BUILD_FOR_WIN32 uint64_t time; - COMPILER_ASSERT(sizeof(uint64_t) == sizeof(FILETIME)); + static_assert(sizeof(uint64_t) == sizeof(FILETIME), "FILETIME is not a uint64"); GetSystemTimeAsFileTime((FILETIME *) &time); return time; #else diff --git a/Sources/Plasma/PubUtilLib/plNetGameLib/Intern.h b/Sources/Plasma/PubUtilLib/plNetGameLib/Intern.h index 42f3c8e3..828ed6c5 100644 --- a/Sources/Plasma/PubUtilLib/plNetGameLib/Intern.h +++ b/Sources/Plasma/PubUtilLib/plNetGameLib/Intern.h @@ -271,7 +271,7 @@ static const char * s_transTypes[] = { "GkAuthSrvIpAddress", }; -COMPILER_ASSERT(arrsize(s_transTypes) == kNumTransTypes); +static_assert(arrsize(s_transTypes) == kNumTransTypes, "Ngl Trans array and enum differ in size"); static long s_perfTransCount[kNumTransTypes]; diff --git a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp index 684b48c4..ff42652a 100644 --- a/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp +++ b/Sources/Plasma/PubUtilLib/plNetGameLib/Private/plNglAuth.cpp @@ -4017,7 +4017,7 @@ bool VaultFindNodeTrans::Recv ( const Auth2Cli_VaultNodeFindReply & reply = *(const Auth2Cli_VaultNodeFindReply *) msg; if (IS_NET_SUCCESS(reply.result)) { - COMPILER_ASSERT(sizeof(unsigned) == sizeof(uint32_t)); + static_assert(sizeof(unsigned) == sizeof(uint32_t), "unsigned is not the same size as uint32_t"); m_nodeIds.Set((unsigned *)reply.nodeIds, reply.nodeIdCount); }