Index: source/lib/alignment.h =================================================================== --- source/lib/alignment.h +++ source/lib/alignment.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2021 Wildfire Games. +/* Copyright (C) 2022 Wildfire Games. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -35,7 +35,7 @@ template inline size_t Align(size_t n) { - cassert(multiple != 0 && ((multiple & (multiple-1)) == 0)); // is power of 2 + static_assert(multiple != 0 && ((multiple & (multiple-1)) == 0)); // is power of 2 return (n + multiple-1) & ~(multiple-1); } Index: source/lib/bits.h =================================================================== --- source/lib/bits.h +++ source/lib/bits.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2010 Wildfire Games. +/* Copyright (C) 2022 Wildfire Games. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -147,7 +147,7 @@ template static inline size_t PopulationCount(T x) { - cassert(!std::numeric_limits::is_signed); + static_assert(!std::numeric_limits::is_signed); const T mask = T(~T(0)); x -= (x >> 1) & (mask/3); // count 2 bits x = (x & (mask/15*3)) + ((x >> 2) & (mask/15*3)); // count 4 bits Index: source/lib/code_annotation.h =================================================================== --- source/lib/code_annotation.h +++ source/lib/code_annotation.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2021 Wildfire Games. +/* Copyright (c) 2022 Wildfire Games. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -191,22 +191,6 @@ #define UID__ PASTE3__(LINE_, __LINE__, _) #define UID2__ PASTE3__(LINE_, __LINE__, _2) - -//----------------------------------------------------------------------------- -// cassert - -/** - * Compile-time assertion. Causes a compile error if the expression - * evaluates to zero/false. - * - * No runtime overhead; may be used anywhere, including file scope. - * Especially useful for testing sizeof types. - * - * @param expr Expression that is expected to evaluate to non-zero at compile-time. - **/ -#define cassert(expr) static_assert((expr), #expr) - - /** * Indicates that a class is noncopyable (usually due to const or reference * members, or because the class works as a singleton). Index: source/lib/debug.cpp =================================================================== --- source/lib/debug.cpp +++ source/lib/debug.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2021 Wildfire Games. +/* Copyright (C) 2022 Wildfire Games. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -181,7 +181,7 @@ // note: the initial state is IDLE. we rely on zero-init because // initializing local static objects from constants may happen when // this is first called, which isn't thread-safe. (see C++ 6.7.4) - cassert(IDLE == 0); + static_assert(IDLE == 0); static volatile intptr_t state; if(!cpu_CAS(&state, IDLE, BUSY)) Index: source/lib/file/archive/archive_zip.cpp =================================================================== --- source/lib/file/archive/archive_zip.cpp +++ source/lib/file/archive/archive_zip.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2021 Wildfire Games. +/* Copyright (C) 2022 Wildfire Games. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -151,7 +151,7 @@ u16 m_e_len; }; -cassert(sizeof(LFH) == 30); +static_assert(sizeof(LFH) == 30); class CDFH @@ -244,7 +244,7 @@ u32 m_lfh_ofs; }; -cassert(sizeof(CDFH) == 46); +static_assert(sizeof(CDFH) == 46); class ECDR @@ -285,7 +285,7 @@ u16 m_comment_len; }; -cassert(sizeof(ECDR) == 22); +static_assert(sizeof(ECDR) == 22); #pragma pack(pop) Index: source/lib/frequency_filter.cpp =================================================================== --- source/lib/frequency_filter.cpp +++ source/lib/frequency_filter.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2018 Wildfire Games. +/* Copyright (C) 2022 Wildfire Games. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -170,7 +170,7 @@ // /\ or \/ in last three history entries bool WasSpike() const { - cassert(m_historySize >= 3); + static_assert(m_historySize >= 3); const double h2 = m_history[m_historySize-3], h1 = m_history[m_historySize-2], h0 = m_history[m_historySize-1]; if(((h2-h1) * (h1-h0)) > 0) // no sign change return false; Index: source/lib/sysdep/arch/amd64/amd64.cpp =================================================================== --- source/lib/sysdep/arch/amd64/amd64.cpp +++ source/lib/sysdep/arch/amd64/amd64.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2010 Wildfire Games. +/* Copyright (C) 2022 Wildfire Games. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -66,13 +66,13 @@ intptr_t cpu_AtomicAdd(volatile intptr_t* location, intptr_t increment) { - cassert(sizeof(intptr_t) == sizeof(int64_t)); + static_assert(sizeof(intptr_t) == sizeof(int64_t)); return OSAtomicAdd64Barrier(increment, (volatile int64_t*)location); } bool cpu_CAS(volatile intptr_t* location, intptr_t expected, intptr_t newValue) { - cassert(sizeof(intptr_t) == sizeof(void*)); + static_assert(sizeof(intptr_t) == sizeof(void*)); return OSAtomicCompareAndSwapPtrBarrier((void*)expected, (void*)newValue, (void* volatile*)location); } Index: source/lib/sysdep/arch/ia32/ia32.cpp =================================================================== --- source/lib/sysdep/arch/ia32/ia32.cpp +++ source/lib/sysdep/arch/ia32/ia32.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2011 Wildfire Games. +/* Copyright (C) 2022 Wildfire Games. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -63,13 +63,13 @@ intptr_t cpu_AtomicAdd(volatile intptr_t* location, intptr_t increment) { - cassert(sizeof(intptr_t) == sizeof(int32_t)); + static_assert(sizeof(intptr_t) == sizeof(int32_t)); return OSAtomicAdd32Barrier(increment, (volatile int32_t*)location); } bool cpu_CAS(volatile intptr_t* location, intptr_t expected, intptr_t newValue) { - cassert(sizeof(intptr_t) == sizeof(void*)); + static_assert(sizeof(intptr_t) == sizeof(void*)); return OSAtomicCompareAndSwapPtrBarrier((void*)expected, (void*)newValue, (void* volatile*)location); } Index: source/lib/sysdep/arch/x86_x64/x86_x64.cpp =================================================================== --- source/lib/sysdep/arch/x86_x64/x86_x64.cpp +++ source/lib/sysdep/arch/x86_x64/x86_x64.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2021 Wildfire Games. +/* Copyright (C) 2022 Wildfire Games. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -72,8 +72,8 @@ static void Invoke_cpuid(CpuidRegs* regs) { - cassert(sizeof(regs->eax) == sizeof(int)); - cassert(sizeof(*regs) == 4*sizeof(int)); + static_assert(sizeof(regs->eax) == sizeof(int)); + static_assert(sizeof(*regs) == 4*sizeof(int)); __cpuidex((int*)regs, regs->eax, regs->ecx); } Index: source/lib/sysdep/cpu.cpp =================================================================== --- source/lib/sysdep/cpu.cpp +++ source/lib/sysdep/cpu.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2010 Wildfire Games. +/* Copyright (C) 2022 Wildfire Games. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -39,12 +39,12 @@ // architectures (IA-32 and AMD64) - just in case the predefined macros // are wrong or misleading. #if ARCH_IA32 -cassert(sizeof(void*) == 4); +static_assert(sizeof(void*) == 4); #elif ARCH_AMD64 -cassert(sizeof(void*) == 8); -cassert(sizeof(i64) == sizeof(intptr_t)); +static_assert(sizeof(void*) == 8); +static_assert(sizeof(i64) == sizeof(intptr_t)); #endif -cassert(sizeof(void*) == sizeof(intptr_t)); +static_assert(sizeof(void*) == sizeof(intptr_t)); Index: source/lib/sysdep/os/win/wdbg_sym.cpp =================================================================== --- source/lib/sysdep/os/win/wdbg_sym.cpp +++ source/lib/sysdep/os/win/wdbg_sym.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2018 Wildfire Games. +/* Copyright (C) 2022 Wildfire Games. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -275,7 +275,7 @@ return ERR::NOT_SUPPORTED; // NOWARN CONTEXT* context = (CONTEXT*)pcontext; - cassert(sizeof(CONTEXT) <= DEBUG_CONTEXT_SIZE); + static_assert(sizeof(CONTEXT) <= DEBUG_CONTEXT_SIZE); memset(context, 0, sizeof(CONTEXT)); context->ContextFlags = CONTEXT_FULL; pRtlCaptureContext(context); Index: source/lib/sysdep/os/win/wdir_watch.cpp =================================================================== --- source/lib/sysdep/os/win/wdir_watch.cpp +++ source/lib/sysdep/os/win/wdir_watch.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2021 Wildfire Games. +/* Copyright (C) 2022 Wildfire Games. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -162,7 +162,7 @@ for(;;) { // convert (non-zero-terminated) BSTR to Path::String - cassert(sizeof(wchar_t) == sizeof(WCHAR)); + static_assert(sizeof(wchar_t) == sizeof(WCHAR)); const size_t length = fni->FileNameLength / sizeof(WCHAR); Path::String name(fni->FileName, length); Index: source/lib/sysdep/os/win/wposix/wmman.cpp =================================================================== --- source/lib/sysdep/os/win/wposix/wmman.cpp +++ source/lib/sysdep/os/win/wposix/wmman.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2011 Wildfire Games. +/* Copyright (C) 2022 Wildfire Games. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -99,7 +99,7 @@ WARN_IF_FALSE(VirtualFree(start, len, MEM_DECOMMIT)); *pp = 0; // make sure *pp won't be misinterpreted as an error - cassert(MAP_FAILED); + static_assert(MAP_FAILED); return INFO::OK; } } Index: source/lobby/scripting/JSInterface_Lobby.cpp =================================================================== --- source/lobby/scripting/JSInterface_Lobby.cpp +++ source/lobby/scripting/JSInterface_Lobby.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2021 Wildfire Games. +/* Copyright (C) 2022 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -158,7 +158,7 @@ const int DIGESTSIZE = crypto_hash_sha256_BYTES; const int ITERATIONS = 1337; - cassert(DIGESTSIZE == 32); + static_assert(DIGESTSIZE == 32); static const unsigned char salt_base[DIGESTSIZE] = { 244, 243, 249, 244, 32, 33, 34, 35, 10, 11, 12, 13, 14, 15, 16, 17, Index: source/ps/FileIo.cpp =================================================================== --- source/ps/FileIo.cpp +++ source/ps/FileIo.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2019 Wildfire Games. +/* Copyright (C) 2022 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -35,7 +35,7 @@ u32 version_le; u32 payloadSize_le; // = file size - sizeof(FileHeader) }; -cassert(sizeof(FileHeader) == 12); +static_assert(sizeof(FileHeader) == 12); #pragma pack(pop) Index: source/ps/ModIo.cpp =================================================================== --- source/ps/ModIo.cpp +++ source/ps/ModIo.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2021 Wildfire Games. +/* Copyright (C) 2022 Wildfire Games. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the @@ -815,7 +815,7 @@ if (sodium_base642bin((unsigned char*)&sig, sizeof sig, msg_sig.c_str(), msg_sig.size(), NULL, &bin_len, NULL, sodium_base64_VARIANT_ORIGINAL) != 0 || bin_len != sizeof sig) FAIL("Failed to decode base64 sig."); - cassert(sizeof pk.keynum == sizeof sig.keynum); + static_assert(sizeof pk.keynum == sizeof sig.keynum); if (memcmp(&pk.keynum, &sig.keynum, sizeof sig.keynum) != 0) continue; // mismatched key, try another one Index: source/renderer/DecalRData.h =================================================================== --- source/renderer/DecalRData.h +++ source/renderer/DecalRData.h @@ -54,7 +54,7 @@ CVector3D m_Normal; CVector2D m_UV; }; - cassert(sizeof(SDecalVertex) == 32); + static_assert(sizeof(SDecalVertex) == 32); CVertexBufferManager::Handle m_VBDecals; CVertexBufferManager::Handle m_VBDecalsIndices; Index: source/renderer/PatchRData.h =================================================================== --- source/renderer/PatchRData.h +++ source/renderer/PatchRData.h @@ -96,7 +96,7 @@ // pad to a power of two u8 m_Padding[8]; }; - cassert(sizeof(SBaseVertex) == 32); + static_assert(sizeof(SBaseVertex) == 32); struct SSideVertex { @@ -105,7 +105,7 @@ // pad to a power of two u8 m_Padding[4]; }; - cassert(sizeof(SSideVertex) == 16); + static_assert(sizeof(SSideVertex) == 16); struct SBlendVertex { @@ -115,7 +115,7 @@ float m_AlphaUVs[2]; CVector3D m_Normal; }; - cassert(sizeof(SBlendVertex) == 32); + static_assert(sizeof(SBlendVertex) == 32); // Mixed Fancy/Simple water vertex description data structure struct SWaterVertex @@ -126,7 +126,7 @@ // pad to a power of two u8 m_Padding[12]; }; - cassert(sizeof(SWaterVertex) == 32); + static_assert(sizeof(SWaterVertex) == 32); // build this renderdata object void Build(); Index: source/renderer/TexturedLineRData.h =================================================================== --- source/renderer/TexturedLineRData.h +++ source/renderer/TexturedLineRData.h @@ -66,7 +66,7 @@ CVector2D m_UV; float padding[3]; // get a pow2 struct size }; - cassert(sizeof(SVertex) == 32); + static_assert(sizeof(SVertex) == 32); /** * Creates a line cap of the specified type @p endCapType at the end of the segment going in direction @p normal, and appends Index: source/renderer/WaterManager.cpp =================================================================== --- source/renderer/WaterManager.cpp +++ source/renderer/WaterManager.cpp @@ -62,7 +62,7 @@ // pad to a power of two u8 m_Padding[5]; }; -cassert(sizeof(SWavesVertex) == 64); +static_assert(sizeof(SWavesVertex) == 64); struct WaveObject { Index: source/simulation2/helpers/HierarchicalPathfinder.h =================================================================== --- source/simulation2/helpers/HierarchicalPathfinder.h +++ source/simulation2/helpers/HierarchicalPathfinder.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2021 Wildfire Games. +/* Copyright (C) 2022 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -171,7 +171,7 @@ std::vector m_RegionsID; // IDs of local regions, 0 (impassable) excluded u16 m_Regions[CHUNK_SIZE][CHUNK_SIZE]; // local region ID per navcell - cassert(CHUNK_SIZE*CHUNK_SIZE/2 < 65536); // otherwise we could overflow m_RegionsID with a checkerboard pattern + static_assert(CHUNK_SIZE*CHUNK_SIZE/2 < 65536); // otherwise we could overflow m_RegionsID with a checkerboard pattern void InitRegions(int ci, int cj, Grid* grid, pass_class_t passClass); Index: source/simulation2/helpers/HierarchicalPathfinder.cpp =================================================================== --- source/simulation2/helpers/HierarchicalPathfinder.cpp +++ source/simulation2/helpers/HierarchicalPathfinder.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2021 Wildfire Games. +/* Copyright (C) 2022 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -151,7 +151,7 @@ u32 si = 0, sj = 0; // sum of i,j coords u32 n = 0; // number of navcells in region - cassert(CHUNK_SIZE < 256); // conservative limit to ensure si and sj don't overflow + static_assert(CHUNK_SIZE < 256); // conservative limit to ensure si and sj don't overflow for (int j = 0; j < CHUNK_SIZE; ++j) {