diff options
author | peterbell10 <peterbell10@live.co.uk> | 2018-02-05 00:07:12 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-05 00:07:12 +0100 |
commit | d3c1c626f569e5aa58085425924cca45927b6199 (patch) | |
tree | c65dee850358467c9afebdd37fcd4f6fb95a475a | |
parent | cChunk and cChunkData: Use vectors for block get and set functions (#4172) (diff) | |
download | cuberite-d3c1c626f569e5aa58085425924cca45927b6199.tar cuberite-d3c1c626f569e5aa58085425924cca45927b6199.tar.gz cuberite-d3c1c626f569e5aa58085425924cca45927b6199.tar.bz2 cuberite-d3c1c626f569e5aa58085425924cca45927b6199.tar.lz cuberite-d3c1c626f569e5aa58085425924cca45927b6199.tar.xz cuberite-d3c1c626f569e5aa58085425924cca45927b6199.tar.zst cuberite-d3c1c626f569e5aa58085425924cca45927b6199.zip |
40 files changed, 274 insertions, 399 deletions
diff --git a/src/Bindings/LuaState.cpp b/src/Bindings/LuaState.cpp index f16b77dc8..6b620a1f1 100644 --- a/src/Bindings/LuaState.cpp +++ b/src/Bindings/LuaState.cpp @@ -994,6 +994,7 @@ void cLuaState::Push(cEntity * a_Entity) return "cEntity"; } } // switch (EntityType) + UNREACHABLE("Unsupported entity type"); }(); tolua_pushusertype(m_LuaState, a_Entity, ClassName); } diff --git a/src/BlockArea.cpp b/src/BlockArea.cpp index bd9ba3a9f..9dce7e916 100644 --- a/src/BlockArea.cpp +++ b/src/BlockArea.cpp @@ -2458,129 +2458,124 @@ void cBlockArea::MergeByStrategy(const cBlockArea & a_Src, int a_RelX, int a_Rel int DstOffZ = std::max(0, a_RelZ); // Offset in Dst where to start writing int SizeZ = std::min(a_Src.GetSizeZ() - SrcOffZ, GetSizeZ() - DstOffZ); // How many blocks to copy - switch (a_Strategy) - { - case cBlockArea::msOverwrite: - { - InternalMergeBlocks<MetasValid, MergeCombinatorOverwrite<MetasValid> >( - GetBlockTypes(), a_Src.GetBlockTypes(), - DstMetas, SrcMetas, - SizeX, SizeY, SizeZ, - SrcOffX, SrcOffY, SrcOffZ, - DstOffX, DstOffY, DstOffZ, - a_Src.GetSizeX(), a_Src.GetSizeY(), a_Src.GetSizeZ(), - m_Size.x, m_Size.y, m_Size.z - ); - break; - } // case msOverwrite - - case cBlockArea::msFillAir: - { - InternalMergeBlocks<MetasValid, MergeCombinatorFillAir<MetasValid> >( - GetBlockTypes(), a_Src.GetBlockTypes(), - DstMetas, SrcMetas, - SizeX, SizeY, SizeZ, - SrcOffX, SrcOffY, SrcOffZ, - DstOffX, DstOffY, DstOffZ, - a_Src.GetSizeX(), a_Src.GetSizeY(), a_Src.GetSizeZ(), - m_Size.x, m_Size.y, m_Size.z - ); - break; - } // case msFillAir - - case cBlockArea::msImprint: - { - InternalMergeBlocks<MetasValid, MergeCombinatorImprint<MetasValid> >( - GetBlockTypes(), a_Src.GetBlockTypes(), - DstMetas, SrcMetas, - SizeX, SizeY, SizeZ, - SrcOffX, SrcOffY, SrcOffZ, - DstOffX, DstOffY, DstOffZ, - a_Src.GetSizeX(), a_Src.GetSizeY(), a_Src.GetSizeZ(), - m_Size.x, m_Size.y, m_Size.z - ); - break; - } // case msImprint - - case cBlockArea::msLake: - { - InternalMergeBlocks<MetasValid, MergeCombinatorLake<MetasValid> >( - GetBlockTypes(), a_Src.GetBlockTypes(), - DstMetas, SrcMetas, - SizeX, SizeY, SizeZ, - SrcOffX, SrcOffY, SrcOffZ, - DstOffX, DstOffY, DstOffZ, - a_Src.GetSizeX(), a_Src.GetSizeY(), a_Src.GetSizeZ(), - m_Size.x, m_Size.y, m_Size.z - ); - break; - } // case msLake - - case cBlockArea::msSpongePrint: - { - InternalMergeBlocks<MetasValid, MergeCombinatorSpongePrint<MetasValid> >( - GetBlockTypes(), a_Src.GetBlockTypes(), - DstMetas, SrcMetas, - SizeX, SizeY, SizeZ, - SrcOffX, SrcOffY, SrcOffZ, - DstOffX, DstOffY, DstOffZ, - a_Src.GetSizeX(), a_Src.GetSizeY(), a_Src.GetSizeZ(), - m_Size.x, m_Size.y, m_Size.z - ); - break; - } // case msSpongePrint - - case cBlockArea::msDifference: - { - InternalMergeBlocks<MetasValid, MergeCombinatorDifference<MetasValid> >( - GetBlockTypes(), a_Src.GetBlockTypes(), - DstMetas, SrcMetas, - SizeX, SizeY, SizeZ, - SrcOffX, SrcOffY, SrcOffZ, - DstOffX, DstOffY, DstOffZ, - a_Src.GetSizeX(), a_Src.GetSizeY(), a_Src.GetSizeZ(), - m_Size.x, m_Size.y, m_Size.z - ); - break; - } // case msDifference - - case cBlockArea::msSimpleCompare: - { - InternalMergeBlocks<MetasValid, MergeCombinatorSimpleCompare<MetasValid> >( - GetBlockTypes(), a_Src.GetBlockTypes(), - DstMetas, SrcMetas, - SizeX, SizeY, SizeZ, - SrcOffX, SrcOffY, SrcOffZ, - DstOffX, DstOffY, DstOffZ, - a_Src.GetSizeX(), a_Src.GetSizeY(), a_Src.GetSizeZ(), - m_Size.x, m_Size.y, m_Size.z - ); - break; - } // case msSimpleCompare - - case cBlockArea::msMask: - { - InternalMergeBlocks<MetasValid, MergeCombinatorMask<MetasValid> >( - GetBlockTypes(), a_Src.GetBlockTypes(), - DstMetas, SrcMetas, - SizeX, SizeY, SizeZ, - SrcOffX, SrcOffY, SrcOffZ, - DstOffX, DstOffY, DstOffZ, - a_Src.GetSizeX(), a_Src.GetSizeY(), a_Src.GetSizeZ(), - m_Size.x, m_Size.y, m_Size.z - ); - break; - } // case msMask - - #ifndef __clang__ // Clang complains about a default case in a switch with all cases covered - default: - { - LOGWARNING("Unknown block area merge strategy: %d", a_Strategy); - ASSERT(!"Unknown block area merge strategy"); - return; - } - #endif - } // switch (a_Strategy) + [&] + { + switch (a_Strategy) + { + case cBlockArea::msOverwrite: + { + InternalMergeBlocks<MetasValid, MergeCombinatorOverwrite<MetasValid> >( + GetBlockTypes(), a_Src.GetBlockTypes(), + DstMetas, SrcMetas, + SizeX, SizeY, SizeZ, + SrcOffX, SrcOffY, SrcOffZ, + DstOffX, DstOffY, DstOffZ, + a_Src.GetSizeX(), a_Src.GetSizeY(), a_Src.GetSizeZ(), + m_Size.x, m_Size.y, m_Size.z + ); + return; + } // case msOverwrite + + case cBlockArea::msFillAir: + { + InternalMergeBlocks<MetasValid, MergeCombinatorFillAir<MetasValid> >( + GetBlockTypes(), a_Src.GetBlockTypes(), + DstMetas, SrcMetas, + SizeX, SizeY, SizeZ, + SrcOffX, SrcOffY, SrcOffZ, + DstOffX, DstOffY, DstOffZ, + a_Src.GetSizeX(), a_Src.GetSizeY(), a_Src.GetSizeZ(), + m_Size.x, m_Size.y, m_Size.z + ); + return; + } // case msFillAir + + case cBlockArea::msImprint: + { + InternalMergeBlocks<MetasValid, MergeCombinatorImprint<MetasValid> >( + GetBlockTypes(), a_Src.GetBlockTypes(), + DstMetas, SrcMetas, + SizeX, SizeY, SizeZ, + SrcOffX, SrcOffY, SrcOffZ, + DstOffX, DstOffY, DstOffZ, + a_Src.GetSizeX(), a_Src.GetSizeY(), a_Src.GetSizeZ(), + m_Size.x, m_Size.y, m_Size.z + ); + return; + } // case msImprint + + case cBlockArea::msLake: + { + InternalMergeBlocks<MetasValid, MergeCombinatorLake<MetasValid> >( + GetBlockTypes(), a_Src.GetBlockTypes(), + DstMetas, SrcMetas, + SizeX, SizeY, SizeZ, + SrcOffX, SrcOffY, SrcOffZ, + DstOffX, DstOffY, DstOffZ, + a_Src.GetSizeX(), a_Src.GetSizeY(), a_Src.GetSizeZ(), + m_Size.x, m_Size.y, m_Size.z + ); + return; + } // case msLake + + case cBlockArea::msSpongePrint: + { + InternalMergeBlocks<MetasValid, MergeCombinatorSpongePrint<MetasValid> >( + GetBlockTypes(), a_Src.GetBlockTypes(), + DstMetas, SrcMetas, + SizeX, SizeY, SizeZ, + SrcOffX, SrcOffY, SrcOffZ, + DstOffX, DstOffY, DstOffZ, + a_Src.GetSizeX(), a_Src.GetSizeY(), a_Src.GetSizeZ(), + m_Size.x, m_Size.y, m_Size.z + ); + return; + } // case msSpongePrint + + case cBlockArea::msDifference: + { + InternalMergeBlocks<MetasValid, MergeCombinatorDifference<MetasValid> >( + GetBlockTypes(), a_Src.GetBlockTypes(), + DstMetas, SrcMetas, + SizeX, SizeY, SizeZ, + SrcOffX, SrcOffY, SrcOffZ, + DstOffX, DstOffY, DstOffZ, + a_Src.GetSizeX(), a_Src.GetSizeY(), a_Src.GetSizeZ(), + m_Size.x, m_Size.y, m_Size.z + ); + return; + } // case msDifference + + case cBlockArea::msSimpleCompare: + { + InternalMergeBlocks<MetasValid, MergeCombinatorSimpleCompare<MetasValid> >( + GetBlockTypes(), a_Src.GetBlockTypes(), + DstMetas, SrcMetas, + SizeX, SizeY, SizeZ, + SrcOffX, SrcOffY, SrcOffZ, + DstOffX, DstOffY, DstOffZ, + a_Src.GetSizeX(), a_Src.GetSizeY(), a_Src.GetSizeZ(), + m_Size.x, m_Size.y, m_Size.z + ); + return; + } // case msSimpleCompare + + case cBlockArea::msMask: + { + InternalMergeBlocks<MetasValid, MergeCombinatorMask<MetasValid> >( + GetBlockTypes(), a_Src.GetBlockTypes(), + DstMetas, SrcMetas, + SizeX, SizeY, SizeZ, + SrcOffX, SrcOffY, SrcOffZ, + DstOffX, DstOffY, DstOffZ, + a_Src.GetSizeX(), a_Src.GetSizeY(), a_Src.GetSizeZ(), + m_Size.x, m_Size.y, m_Size.z + ); + return; + } // case msMask + } // switch (a_Strategy) + UNREACHABLE("Unsupported block area merge strategy"); + }(); if (HasBlockEntities()) { diff --git a/src/BlockID.cpp b/src/BlockID.cpp index a6f846911..acba8db27 100644 --- a/src/BlockID.cpp +++ b/src/BlockID.cpp @@ -388,12 +388,7 @@ AString DamageTypeToString(eDamageType a_DamageType) case dtSuffocating: return "dtSuffocation"; case dtExplosion: return "dtExplosion"; } - - // Unknown damage type: - ASSERT(!"Unknown DamageType"); - #ifndef __clang__ - return Printf("dtUnknown_%d", static_cast<int>(a_DamageType)); - #endif + UNREACHABLE("Unsupported damage type"); } diff --git a/src/Blocks/BlockButton.h b/src/Blocks/BlockButton.h index 2b646c6e8..ed4e12482 100644 --- a/src/Blocks/BlockButton.h +++ b/src/Blocks/BlockButton.h @@ -92,10 +92,7 @@ public: return 0x0; } } - #if !defined(__clang__) - ASSERT(!"Unknown BLOCK_FACE"); - return 0; - #endif + UNREACHABLE("Unsupported block face"); } inline static eBlockFace BlockMetaDataToBlockFace(NIBBLETYPE a_Meta) diff --git a/src/Blocks/BlockCocoaPod.h b/src/Blocks/BlockCocoaPod.h index 035cc2f4f..4a1fb8c10 100644 --- a/src/Blocks/BlockCocoaPod.h +++ b/src/Blocks/BlockCocoaPod.h @@ -82,10 +82,7 @@ public: return 0; } } - #if !defined(__clang__) - ASSERT(!"Unknown BLOCK_FACE"); - return 0; - #endif + UNREACHABLE("Unsupported block face"); } virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) override diff --git a/src/Blocks/BlockLadder.h b/src/Blocks/BlockLadder.h index a17cfc1a1..29c0cf2b7 100644 --- a/src/Blocks/BlockLadder.h +++ b/src/Blocks/BlockLadder.h @@ -60,10 +60,7 @@ public: return 0x2; } } - #if !defined(__clang__) - ASSERT(!"Unknown BLOCK_FACE"); - return 0; - #endif + UNREACHABLE("Unsupported block face"); } static eBlockFace MetaDataToDirection(NIBBLETYPE a_MetaData) diff --git a/src/Blocks/BlockLever.h b/src/Blocks/BlockLever.h index 6750649ae..6cb80222e 100644 --- a/src/Blocks/BlockLever.h +++ b/src/Blocks/BlockLever.h @@ -65,10 +65,7 @@ public: case BLOCK_FACE_YM: return 0x0; case BLOCK_FACE_NONE: return 0x6; } - #if !defined(__clang__) - ASSERT(!"Unknown BLOCK_FACE"); - return 0; - #endif + UNREACHABLE("Unsupported block face"); } inline static eBlockFace BlockMetaDataToBlockFace(NIBBLETYPE a_Meta) diff --git a/src/Blocks/BlockQuartz.h b/src/Blocks/BlockQuartz.h index c2435cd5e..c87240cf1 100644 --- a/src/Blocks/BlockQuartz.h +++ b/src/Blocks/BlockQuartz.h @@ -63,10 +63,7 @@ public: return a_QuartzMeta; // No idea, give a special meta (all sides the same) } } - #if !defined(__clang__) - ASSERT(!"Unknown BLOCK_FACE"); - return 0; - #endif + UNREACHABLE("Unsupported block face"); } virtual ColourID GetMapBaseColourID(NIBBLETYPE a_Meta) override diff --git a/src/Blocks/BlockSideways.h b/src/Blocks/BlockSideways.h index df94b6ac3..5bc7874b4 100644 --- a/src/Blocks/BlockSideways.h +++ b/src/Blocks/BlockSideways.h @@ -64,10 +64,7 @@ public: return a_Meta | 0xC; // No idea, give a special meta } } - #if !defined(__clang__) - ASSERT(!"Unknown BLOCK_FACE"); - return 0; - #endif + UNREACHABLE("Unsupported block face"); } } ; diff --git a/src/Blocks/BlockTrapdoor.h b/src/Blocks/BlockTrapdoor.h index b3703299f..f8e5df09a 100644 --- a/src/Blocks/BlockTrapdoor.h +++ b/src/Blocks/BlockTrapdoor.h @@ -83,10 +83,7 @@ public: return 0; } } - #if !defined(__clang__) - ASSERT(!"Unknown BLOCK_FACE"); - return 0; - #endif + UNREACHABLE("Unsupported block face"); } inline static eBlockFace BlockMetaDataToBlockFace(NIBBLETYPE a_Meta) diff --git a/src/Blocks/BlockTripwireHook.h b/src/Blocks/BlockTripwireHook.h index f0f6ff722..d544fff86 100644 --- a/src/Blocks/BlockTripwireHook.h +++ b/src/Blocks/BlockTripwireHook.h @@ -45,10 +45,7 @@ public: return 0x0; } } - #if !defined(__clang__) - ASSERT(!"Unknown BLOCK_FACE"); - return 0; - #endif + UNREACHABLE("Unsupported block face"); } inline static eBlockFace MetadataToDirection(NIBBLETYPE a_Meta) diff --git a/src/Defines.h b/src/Defines.h index 7a7f4c598..758c416e8 100644 --- a/src/Defines.h +++ b/src/Defines.h @@ -277,8 +277,7 @@ inline const char * ClickActionToString(int a_ClickAction) case caUnknown: return "caUnknown"; } - ASSERT(!"Unknown click action"); - return "caUnknown"; + UNREACHABLE("Unknown click action"); } @@ -299,12 +298,9 @@ inline eBlockFace MirrorBlockFaceY(eBlockFace a_BlockFace) case BLOCK_FACE_YP: { return a_BlockFace; - }; + } } - #if !defined(__clang__) - ASSERT(!"Unknown BLOCK_FACE"); - return a_BlockFace; - #endif + UNREACHABLE("Unsupported block face"); } @@ -327,10 +323,7 @@ inline eBlockFace RotateBlockFaceCCW(eBlockFace a_BlockFace) return a_BlockFace; } } - #if !defined(__clang__) - ASSERT(!"Unknown BLOCK_FACE"); - return a_BlockFace; - #endif + UNREACHABLE("Unsupported block face"); } @@ -350,12 +343,9 @@ inline eBlockFace RotateBlockFaceCW(eBlockFace a_BlockFace) case BLOCK_FACE_YP: { return a_BlockFace; - }; + } } - #if !defined(__clang__) - ASSERT(!"Unknown BLOCK_FACE"); - return a_BlockFace; - #endif + UNREACHABLE("Unsupported block face"); } @@ -374,10 +364,7 @@ inline eBlockFace ReverseBlockFace(eBlockFace a_BlockFace) case BLOCK_FACE_ZM: return BLOCK_FACE_ZP; case BLOCK_FACE_NONE: return a_BlockFace; } - #if !defined(__clang__) - ASSERT(!"Unknown BLOCK_FACE"); - return a_BlockFace; - #endif + UNREACHABLE("Unsupported block face"); } @@ -397,10 +384,7 @@ inline AString BlockFaceToString(eBlockFace a_BlockFace) case BLOCK_FACE_ZP: return "BLOCK_FACE_ZP"; case BLOCK_FACE_NONE: return "BLOCK_FACE_NONE"; } - // clang optimisises this line away then warns that it has done so. - #if !defined(__clang__) - return Printf("Unknown BLOCK_FACE: %d", a_BlockFace); - #endif + UNREACHABLE("Unsupported block face"); } diff --git a/src/Entities/ArrowEntity.cpp b/src/Entities/ArrowEntity.cpp index 2dc329f30..2db0baad6 100644 --- a/src/Entities/ArrowEntity.cpp +++ b/src/Entities/ArrowEntity.cpp @@ -66,10 +66,7 @@ bool cArrowEntity::CanPickup(const cPlayer & a_Player) const case psInSurvivalOrCreative: return (a_Player.IsGameModeSurvival() || a_Player.IsGameModeCreative()); case psInCreative: return a_Player.IsGameModeCreative(); } - ASSERT(!"Unhandled pickup state"); - #ifndef __clang__ - return false; - #endif + UNREACHABLE("Unsupported arrow pickup state"); } diff --git a/src/Entities/Boat.cpp b/src/Entities/Boat.cpp index 4021f9ce8..20947dc44 100644 --- a/src/Entities/Boat.cpp +++ b/src/Entities/Boat.cpp @@ -207,10 +207,7 @@ AString cBoat::MaterialToString(eMaterial a_Material) case bmAcacia: return "acacia"; case bmDarkOak: return "dark_oak"; } - ASSERT(!"Unhandled boat material"); - #ifndef __clang__ - return "oak"; - #endif + UNREACHABLE("Unsupported boat material"); } @@ -264,9 +261,7 @@ cItem cBoat::MaterialToItem(eMaterial a_Material) case bmAcacia: return cItem(E_ITEM_ACACIA_BOAT); case bmDarkOak: return cItem(E_ITEM_DARK_OAK_BOAT); } - #ifndef __clang__ - return cItem(E_ITEM_BOAT); - #endif + UNREACHABLE("Unsupported boat material"); } diff --git a/src/Entities/Entity.cpp b/src/Entities/Entity.cpp index c811988bf..707f75cf1 100644 --- a/src/Entities/Entity.cpp +++ b/src/Entities/Entity.cpp @@ -640,10 +640,7 @@ bool cEntity::ArmorCoversAgainst(eDamageType a_DamageType) return true; } } - ASSERT(!"Invalid damage type!"); - #ifndef __clang__ - return false; - #endif + UNREACHABLE("Unsupported damage type"); } diff --git a/src/Entities/EntityEffect.cpp b/src/Entities/EntityEffect.cpp index fcb1fdfdb..8f0ecc395 100644 --- a/src/Entities/EntityEffect.cpp +++ b/src/Entities/EntityEffect.cpp @@ -217,11 +217,7 @@ std::unique_ptr<cEntityEffect> cEntityEffect::CreateEntityEffect(cEntityEffect:: case cEntityEffect::effWeakness: return cpp14::make_unique<cEntityEffectWeakness >(a_Duration, a_Intensity, a_DistanceModifier); case cEntityEffect::effWither: return cpp14::make_unique<cEntityEffectWither >(a_Duration, a_Intensity, a_DistanceModifier); } - - ASSERT(!"Unhandled entity effect type!"); - #ifndef __clang__ - return {}; - #endif + UNREACHABLE("Unsupported entity effect"); } diff --git a/src/Entities/HangingEntity.h b/src/Entities/HangingEntity.h index 113d195f9..35b0117b0 100644 --- a/src/Entities/HangingEntity.h +++ b/src/Entities/HangingEntity.h @@ -60,40 +60,34 @@ protected: /** Converts protocol hanging item facing to eBlockFace values */ inline static eBlockFace ProtocolFaceToBlockFace(Byte a_ProtocolFace) { - eBlockFace Dir; - // The client uses different values for item frame directions and block faces. Our constants are for the block faces, so we convert them here to item frame faces switch (a_ProtocolFace) { - case 0: Dir = BLOCK_FACE_ZP; break; - case 2: Dir = BLOCK_FACE_ZM; break; - case 1: Dir = BLOCK_FACE_XM; break; - case 3: Dir = BLOCK_FACE_XP; break; + case 0: return BLOCK_FACE_ZP; + case 2: return BLOCK_FACE_ZM; + case 1: return BLOCK_FACE_XM; + case 3: return BLOCK_FACE_XP; default: { LOGINFO("Invalid facing (%d) in a cHangingEntity, adjusting to BLOCK_FACE_XP.", a_ProtocolFace); ASSERT(!"Tried to convert a bad facing!"); - Dir = cHangingEntity::ProtocolFaceToBlockFace(3); + return cHangingEntity::ProtocolFaceToBlockFace(3); } } - - return Dir; } /** Converts eBlockFace values to protocol hanging item faces */ inline static Byte BlockFaceToProtocolFace(eBlockFace a_BlockFace) { - Byte Dir; - // The client uses different values for item frame directions and block faces. Our constants are for the block faces, so we convert them here to item frame faces switch (a_BlockFace) { - case BLOCK_FACE_ZP: Dir = 0; break; - case BLOCK_FACE_ZM: Dir = 2; break; - case BLOCK_FACE_XM: Dir = 1; break; - case BLOCK_FACE_XP: Dir = 3; break; + case BLOCK_FACE_ZP: return 0; + case BLOCK_FACE_ZM: return 2; + case BLOCK_FACE_XM: return 1; + case BLOCK_FACE_XP: return 3; case BLOCK_FACE_YP: case BLOCK_FACE_YM: case BLOCK_FACE_NONE: @@ -102,19 +96,10 @@ protected: // LOGINFO("Invalid facing (%d) in a cHangingEntity, adjusting to BLOCK_FACE_XP.", a_BlockFace); // ASSERT(!"Tried to convert a bad facing!"); - Dir = cHangingEntity::BlockFaceToProtocolFace(BLOCK_FACE_XP); - break; + return cHangingEntity::BlockFaceToProtocolFace(BLOCK_FACE_XP); } - #if !defined(__clang__) - default: - { - ASSERT(!"Unknown BLOCK_FACE"); - return 0; - } - #endif } - - return Dir; + UNREACHABLE("Unsupported block face"); } }; // tolua_export diff --git a/src/Entities/Player.cpp b/src/Entities/Player.cpp index 7b6719f55..b4bf95f5b 100644 --- a/src/Entities/Player.cpp +++ b/src/Entities/Player.cpp @@ -1060,36 +1060,31 @@ void cPlayer::KilledBy(TakeDamageInfo & a_TDI) if ((a_TDI.Attacker == nullptr) && m_World->ShouldBroadcastDeathMessages()) { - AString DamageText; - switch (a_TDI.DamageType) - { - case dtRangedAttack: DamageText = "was shot"; break; - case dtLightning: DamageText = "was plasmified by lightining"; break; - case dtFalling: DamageText = GetRandomProvider().RandBool() ? "fell to death" : "hit the ground too hard"; break; - case dtDrowning: DamageText = "drowned"; break; - case dtSuffocating: DamageText = GetRandomProvider().RandBool() ? "git merge'd into a block" : "fused with a block"; break; - case dtStarving: DamageText = "forgot the importance of food"; break; - case dtCactusContact: DamageText = "was impaled on a cactus"; break; - case dtLavaContact: DamageText = "was melted by lava"; break; - case dtPoisoning: DamageText = "died from septicaemia"; break; - case dtWithering: DamageText = "is a husk of their former selves"; break; - case dtOnFire: DamageText = "forgot to stop, drop, and roll"; break; - case dtFireContact: DamageText = "burnt themselves to death"; break; - case dtInVoid: DamageText = "somehow fell out of the world"; break; - case dtPotionOfHarming: DamageText = "was magicked to death"; break; - case dtEnderPearl: DamageText = "misused an ender pearl"; break; - case dtAdmin: DamageText = "was administrator'd"; break; - case dtExplosion: DamageText = "blew up"; break; - case dtAttack: DamageText = "was attacked by thin air"; break; - #ifndef __clang__ - default: + const AString DamageText = [&] { - ASSERT(!"Unknown damage type"); - DamageText = "died, somehow; we've no idea how though"; - break; - } - #endif // __clang__ - } + switch (a_TDI.DamageType) + { + case dtRangedAttack: return "was shot"; + case dtLightning: return "was plasmified by lightining"; + case dtFalling: return GetRandomProvider().RandBool() ? "fell to death" : "hit the ground too hard"; + case dtDrowning: return "drowned"; + case dtSuffocating: return GetRandomProvider().RandBool() ? "git merge'd into a block" : "fused with a block"; + case dtStarving: return "forgot the importance of food"; + case dtCactusContact: return "was impaled on a cactus"; + case dtLavaContact: return "was melted by lava"; + case dtPoisoning: return "died from septicaemia"; + case dtWithering: return "is a husk of their former selves"; + case dtOnFire: return "forgot to stop, drop, and roll"; + case dtFireContact: return "burnt themselves to death"; + case dtInVoid: return "somehow fell out of the world"; + case dtPotionOfHarming: return "was magicked to death"; + case dtEnderPearl: return "misused an ender pearl"; + case dtAdmin: return "was administrator'd"; + case dtExplosion: return "blew up"; + case dtAttack: return "was attacked by thin air"; + } + UNREACHABLE("Unsupported damage type"); + }(); AString DeathMessage = Printf("%s %s", GetName().c_str(), DamageText.c_str()); PluginManager->CallHookKilled(*this, a_TDI, DeathMessage); if (DeathMessage != AString("")) diff --git a/src/Entities/ProjectileEntity.cpp b/src/Entities/ProjectileEntity.cpp index 0649e5b95..915475f2a 100644 --- a/src/Entities/ProjectileEntity.cpp +++ b/src/Entities/ProjectileEntity.cpp @@ -356,10 +356,7 @@ AString cProjectileEntity::GetMCAClassName(void) const case pkFirework: return "Firework"; case pkFishingFloat: return ""; // Unknown, perhaps MC doesn't save this? } - ASSERT(!"Unhandled projectile entity kind!"); - #ifndef __clang__ - return ""; - #endif + UNREACHABLE("Unsupported projectile kind"); } diff --git a/src/Generating/MineShafts.cpp b/src/Generating/MineShafts.cpp index 755fa23a3..5a9fd6368 100644 --- a/src/Generating/MineShafts.cpp +++ b/src/Generating/MineShafts.cpp @@ -767,33 +767,30 @@ void cMineShaftCorridor::PlaceChest(cChunkDesc & a_ChunkDesc) int BlockZ = a_ChunkDesc.GetChunkZ() * cChunkDef::Width; int x, z; NIBBLETYPE Meta = 0; - switch (m_Direction) + [&] { - case dirXM: - case dirXP: + switch (m_Direction) { - x = m_BoundingBox.p1.x + m_ChestPosition - BlockX; - z = m_BoundingBox.p1.z - BlockZ; - Meta = E_META_CHEST_FACING_ZP; - break; - } + case dirXM: + case dirXP: + { + x = m_BoundingBox.p1.x + m_ChestPosition - BlockX; + z = m_BoundingBox.p1.z - BlockZ; + Meta = E_META_CHEST_FACING_ZP; + return; + } - case dirZM: - case dirZP: - { - x = m_BoundingBox.p1.x - BlockX; - z = m_BoundingBox.p1.z + m_ChestPosition - BlockZ; - Meta = E_META_CHEST_FACING_XP; - break; - } - #if !defined(__clang__) - default: - { - ASSERT(!"Unknown direction"); - return; - } - #endif - } // switch (Dir) + case dirZM: + case dirZP: + { + x = m_BoundingBox.p1.x - BlockX; + z = m_BoundingBox.p1.z + m_ChestPosition - BlockZ; + Meta = E_META_CHEST_FACING_XP; + return; + } + } // switch (Dir) + UNREACHABLE("Unsupported corridor direction"); + }(); if ( (x >= 0) && (x < cChunkDef::Width) && diff --git a/src/Generating/PiecePool.cpp b/src/Generating/PiecePool.cpp index 201c70afd..4b4303516 100644 --- a/src/Generating/PiecePool.cpp +++ b/src/Generating/PiecePool.cpp @@ -200,10 +200,7 @@ Vector3i cPiece::cConnector::AddDirection(const Vector3i & a_Pos, eDirection a_D case dirYP_XP_ZM: return Vector3i(a_Pos.x, a_Pos.y + 1, a_Pos.z); case dirYP_XP_ZP: return Vector3i(a_Pos.x, a_Pos.y + 1, a_Pos.z); } - #if !defined(__clang__) - ASSERT(!"Unknown connector direction"); - return a_Pos; - #endif + UNREACHABLE("Unsupported connector direction"); } @@ -229,10 +226,7 @@ const char * cPiece::cConnector::DirectionToString(eDirection a_Direction) case dirYP_XP_ZM: return "y+x+z-"; case dirYP_XP_ZP: return "y+x+z+"; } - #if !defined(__clang__) - ASSERT(!"Unknown connector direction"); - return "<unknown>"; - #endif + UNREACHABLE("Unsupported connector direction"); } @@ -288,10 +282,7 @@ cPiece::cConnector::eDirection cPiece::cConnector::RotateDirection(eDirection a_ case dirYP_XP_ZM: return dirYP_XM_ZP; case dirYP_XP_ZP: return dirYP_XM_ZM; } - #if !defined(__clang__) - ASSERT(!"Unknown connector direction"); - return a_Direction; - #endif + UNREACHABLE("Unsupported connector direction"); } @@ -318,10 +309,7 @@ cPiece::cConnector::eDirection cPiece::cConnector::RotateDirectionCCW(eDirection case dirYP_XP_ZM: return dirYP_XM_ZM; case dirYP_XP_ZP: return dirYP_XP_ZM; } - #if !defined(__clang__) - ASSERT(!"Unknown connector direction"); - return a_Direction; - #endif + UNREACHABLE("Unsupported connector direction"); } @@ -348,10 +336,7 @@ cPiece::cConnector::eDirection cPiece::cConnector::RotateDirectionCW(eDirection case dirYP_XP_ZM: return dirYP_XP_ZP; case dirYP_XP_ZP: return dirYP_XM_ZP; } - #if !defined(__clang__) - ASSERT(!"Unknown connector direction"); - return a_Direction; - #endif + UNREACHABLE("Unsupported connector direction"); } diff --git a/src/Generating/StructGen.cpp b/src/Generating/StructGen.cpp index d0e8da26a..918467f93 100644 --- a/src/Generating/StructGen.cpp +++ b/src/Generating/StructGen.cpp @@ -274,6 +274,7 @@ int cStructGenTrees::GetNumTrees( return 0; } } + UNREACHABLE("Unsupported biome"); }; int NumTrees = 0; diff --git a/src/Globals.h b/src/Globals.h index e48c6dbfe..e37f6dc60 100644 --- a/src/Globals.h +++ b/src/Globals.h @@ -352,6 +352,9 @@ template class SizeChecker<UInt8, 1>; #define assert_test(x) ( !!(x) || (assert(!#x), exit(1), 0)) #endif +/** Use to mark code that should be impossible to reach. */ +#define UNREACHABLE(x) do { FLOGERROR("Hit unreachable code: {0}, file {1}, line {2}", #x, __FILE__, __LINE__); PrintStackTrace(); std::terminate(); } while (false) + diff --git a/src/HTTP/NameValueParser.cpp b/src/HTTP/NameValueParser.cpp index 94df82438..ca5c4baab 100644 --- a/src/HTTP/NameValueParser.cpp +++ b/src/HTTP/NameValueParser.cpp @@ -404,10 +404,7 @@ bool cNameValueParser::Finish(void) return true; } } - ASSERT(!"Unhandled parser state!"); - #ifndef __clang__ - return false; - #endif + UNREACHABLE("Unsupported name value parser state"); } diff --git a/src/Items/ItemAxe.h b/src/Items/ItemAxe.h index aeba22cf4..1dfd2aeca 100644 --- a/src/Items/ItemAxe.h +++ b/src/Items/ItemAxe.h @@ -27,6 +27,7 @@ public: case dlaBreakBlock: return 1; case dlaBreakBlockInstant: return 0; } + UNREACHABLE("Unsupported durability loss action"); } diff --git a/src/Items/ItemHoe.h b/src/Items/ItemHoe.h index 8fe53c343..a0bf44a93 100644 --- a/src/Items/ItemHoe.h +++ b/src/Items/ItemHoe.h @@ -75,5 +75,6 @@ public: case dlaBreakBlock: return 0; case dlaBreakBlockInstant: return 0; } + UNREACHABLE("Unsupported durability loss action"); } } ; diff --git a/src/Items/ItemPickaxe.h b/src/Items/ItemPickaxe.h index 84fa655fc..a23e9ec6d 100644 --- a/src/Items/ItemPickaxe.h +++ b/src/Items/ItemPickaxe.h @@ -26,6 +26,7 @@ public: case dlaBreakBlock: return 1; case dlaBreakBlockInstant: return 0; } + UNREACHABLE("Unsupported durability loss action"); } diff --git a/src/Items/ItemShears.h b/src/Items/ItemShears.h index bebc85c92..6cbb37b2a 100644 --- a/src/Items/ItemShears.h +++ b/src/Items/ItemShears.h @@ -69,6 +69,7 @@ public: case dlaBreakBlock: return 0; case dlaBreakBlockInstant: return 1; } + UNREACHABLE("Unsupported durability loss action"); } diff --git a/src/Items/ItemShovel.h b/src/Items/ItemShovel.h index a39e6ecac..49ecf3348 100644 --- a/src/Items/ItemShovel.h +++ b/src/Items/ItemShovel.h @@ -31,6 +31,7 @@ public: case dlaBreakBlock: return 1; case dlaBreakBlockInstant: return 0; } + UNREACHABLE("Unsupported durability loss action"); } diff --git a/src/Items/ItemSword.h b/src/Items/ItemSword.h index 773b84388..06543c37e 100644 --- a/src/Items/ItemSword.h +++ b/src/Items/ItemSword.h @@ -50,6 +50,7 @@ public: case dlaBreakBlock: return 2; case dlaBreakBlockInstant: return 0; } + UNREACHABLE("Unsupported durability loss action"); } diff --git a/src/MobCensus.cpp b/src/MobCensus.cpp index 79b5176d2..5340c089d 100644 --- a/src/MobCensus.cpp +++ b/src/MobCensus.cpp @@ -48,10 +48,7 @@ int cMobCensus::GetCapMultiplier(cMonster::eFamily a_MobFamily) return -1; } } - #if !defined(__clang__) - ASSERT(!"Unknown mob family"); - return -1; - #endif + UNREACHABLE("Unsupported mob family"); } diff --git a/src/Mobs/PathFinder.cpp b/src/Mobs/PathFinder.cpp index 93664b596..a4f237fbd 100644 --- a/src/Mobs/PathFinder.cpp +++ b/src/Mobs/PathFinder.cpp @@ -152,14 +152,8 @@ ePathFinderStatus cPathFinder::GetNextWayPoint(cChunk & a_Chunk, const Vector3d return ePathFinderStatus::PATH_FOUND; } } - #ifndef __clang__ - default: - { - return ePathFinderStatus::PATH_FOUND; - // Fixes GCC warning: "control reaches end of non-void function". - } - #endif } + UNREACHABLE("Unsupported path finder status"); } diff --git a/src/Protocol/PacketID.cpp b/src/Protocol/PacketID.cpp index f401f856e..47d274f25 100644 --- a/src/Protocol/PacketID.cpp +++ b/src/Protocol/PacketID.cpp @@ -79,11 +79,7 @@ UInt32 cProtocol_1_9_0::GetPacketId(eOutgoingPackets a_Packet) case sendWindowOpen: return 0x13; case sendWindowProperty: return 0x15; } - ASSERT(!"Retrieving packet ID for unknown packet type"); - #ifndef __clang__ - LOGWARNING("Retrieving packet ID for unknown packet type %d!", a_Packet); - return 0; - #endif + UNREACHABLE("Unsupported outgoing packet type"); } diff --git a/src/Scoreboard.cpp b/src/Scoreboard.cpp index eec20e31c..e2687e7af 100644 --- a/src/Scoreboard.cpp +++ b/src/Scoreboard.cpp @@ -30,13 +30,8 @@ AString cObjective::TypeToString(eType a_Type) case otStatBlockMine: return "stat.mineBlock"; case otStatEntityKill: return "stat.killEntity"; case otStatEntityKilledBy: return "stat.entityKilledBy"; - - // clang optimisises this line away then warns that it has done so. - #if !defined(__clang__) - default: return ""; - #endif } - + UNREACHABLE("Unsupported objective type"); } diff --git a/src/World.cpp b/src/World.cpp index 6c806ec6e..1b7bc8643 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -492,11 +492,7 @@ int cWorld::GetDefaultWeatherInterval(eWeather a_Weather) return Random.RandInt(m_MinThunderStormTicks, m_MaxThunderStormTicks); } } - - #ifndef __clang__ - ASSERT(!"Unknown weather"); - return -1; - #endif + UNREACHABLE("Unsupported weather"); } @@ -851,19 +847,17 @@ eWeather cWorld::ChooseNewWeather() switch (m_Weather) { case eWeather_Sunny: - case eWeather_ThunderStorm: return eWeather_Rain; - + case eWeather_ThunderStorm: + { + return eWeather_Rain; + } case eWeather_Rain: { // 1 / 8 chance of turning into a thunderstorm return GetRandomProvider().RandBool(0.125) ? eWeather_ThunderStorm : eWeather_Sunny; } } - - #ifndef __clang__ - ASSERT(!"Unknown weather"); - return eWeather_Sunny; - #endif + UNREACHABLE("Unsupported weather"); } diff --git a/src/WorldStorage/FastNBT.cpp b/src/WorldStorage/FastNBT.cpp index 237773733..99148e126 100644 --- a/src/WorldStorage/FastNBT.cpp +++ b/src/WorldStorage/FastNBT.cpp @@ -35,6 +35,35 @@ static const int MAX_LIST_ITEMS = 10000; //////////////////////////////////////////////////////////////////////////////// // cNBTParseErrorCategory: +namespace +{ + +class cNBTParseErrorCategory final : + public std::error_category +{ + cNBTParseErrorCategory() = default; +public: + /** Category name */ + virtual const char * name() const NOEXCEPT override + { + return "NBT parse error"; + } + + /** Maps a parse error code to an error message */ + virtual AString message(int a_Condition) const override; + + /** Returns the canonical error category instance. */ + static const cNBTParseErrorCategory & Get() NOEXCEPT + { + static cNBTParseErrorCategory Category; + return Category; + } +}; + + + + + AString cNBTParseErrorCategory::message(int a_Condition) const { switch (static_cast<eNBTParseError>(a_Condition)) @@ -91,22 +120,19 @@ AString cNBTParseErrorCategory::message(int a_Condition) const { return "Unknown tag"; } + } + UNREACHABLE("Unsupported nbt parse error"); +} - #ifdef __clang__ - #pragma clang diagnostic push - #pragma clang diagnostic ignored "-Wcovered-switch-default" - #pragma clang diagnostic ignored "-Wunreachable-code" - #endif +} // namespace (anonymous) - default: - { - return "<unrecognized error>"; - } - #ifdef __clang__ - #pragma clang diagnostic pop - #endif - } + + + +std::error_code make_error_code(eNBTParseError a_Err) NOEXCEPT +{ + return { static_cast<int>(a_Err), cNBTParseErrorCategory::Get() }; } @@ -337,14 +363,12 @@ eNBTParseError cParsedNBT::ReadTag(void) return eNBTParseError::npSuccess; } - #if !defined(__clang__) - default: - #endif case TAG_Min: { return eNBTParseError::npUnknownTag; } } // switch (iType) + UNREACHABLE("Unsupported nbt tag type"); } #undef CASE_SIMPLE_TAG diff --git a/src/WorldStorage/FastNBT.h b/src/WorldStorage/FastNBT.h index 1894903ac..0185a49ec 100644 --- a/src/WorldStorage/FastNBT.h +++ b/src/WorldStorage/FastNBT.h @@ -125,41 +125,8 @@ enum class eNBTParseError npUnknownTag, }; - - - - -class cNBTParseErrorCategory final: - public std::error_category -{ - cNBTParseErrorCategory() = default; -public: - /** Category name */ - virtual const char * name() const NOEXCEPT override - { - return "NBT parse error"; - } - - /** Maps a parse error code to an error message */ - virtual AString message(int a_Condition) const override; - - /** Returns the canonical error category instance. */ - static const cNBTParseErrorCategory & Get() - { - static cNBTParseErrorCategory Category; - return Category; - } -}; - - - - - // The following is required to make an error_code constructible from an eNBTParseError -inline std::error_code make_error_code(eNBTParseError a_Err) NOEXCEPT -{ - return { static_cast<int>(a_Err), cNBTParseErrorCategory::Get() }; -} +std::error_code make_error_code(eNBTParseError a_Err) NOEXCEPT; namespace std { diff --git a/src/mbedTLS++/SslConfig.cpp b/src/mbedTLS++/SslConfig.cpp index 9dec49776..c97e29cda 100644 --- a/src/mbedTLS++/SslConfig.cpp +++ b/src/mbedTLS++/SslConfig.cpp @@ -145,10 +145,8 @@ void cSslConfig::SetAuthMode(const eSslAuthMode a_AuthMode) case eSslAuthMode::Optional: return MBEDTLS_SSL_VERIFY_OPTIONAL; case eSslAuthMode::Required: return MBEDTLS_SSL_VERIFY_REQUIRED; case eSslAuthMode::Unset: return MBEDTLS_SSL_VERIFY_UNSET; - #ifndef __clang__ - default: return MBEDTLS_SSL_VERIFY_OPTIONAL; - #endif } + UNREACHABLE("Unsupported SSL auth mode"); }(); mbedtls_ssl_conf_authmode(&m_Config, Mode); diff --git a/tests/HTTP/CMakeLists.txt b/tests/HTTP/CMakeLists.txt index 3f0f4b6f8..4ca163864 100644 --- a/tests/HTTP/CMakeLists.txt +++ b/tests/HTTP/CMakeLists.txt @@ -15,6 +15,8 @@ set (HTTP_SRCS ${CMAKE_SOURCE_DIR}/src/HTTP/TransferEncodingParser.cpp ${CMAKE_SOURCE_DIR}/src/HTTP/UrlClient.cpp ${CMAKE_SOURCE_DIR}/src/HTTP/UrlParser.cpp + ${CMAKE_SOURCE_DIR}/src/OSSupport/StackTrace.cpp + ${CMAKE_SOURCE_DIR}/src/OSSupport/WinStackWalker.cpp ${CMAKE_SOURCE_DIR}/src/StringUtils.cpp ) @@ -25,6 +27,8 @@ set (HTTP_HDRS ${CMAKE_SOURCE_DIR}/src/HTTP/TransferEncodingParser.h ${CMAKE_SOURCE_DIR}/src/HTTP/UrlClient.h ${CMAKE_SOURCE_DIR}/src/HTTP/UrlParser.h + ${CMAKE_SOURCE_DIR}/src/OSSupport/StackTrace.h + ${CMAKE_SOURCE_DIR}/src/OSSupport/WinStackWalker.h ${CMAKE_SOURCE_DIR}/src/StringUtils.h ) diff --git a/tests/Network/CMakeLists.txt b/tests/Network/CMakeLists.txt index 91091b5cf..84c49bfed 100644 --- a/tests/Network/CMakeLists.txt +++ b/tests/Network/CMakeLists.txt @@ -18,7 +18,9 @@ set (Network_SRCS ${CMAKE_SOURCE_DIR}/src/OSSupport/NetworkLookup.cpp ${CMAKE_SOURCE_DIR}/src/OSSupport/NetworkSingleton.cpp ${CMAKE_SOURCE_DIR}/src/OSSupport/ServerHandleImpl.cpp + ${CMAKE_SOURCE_DIR}/src/OSSupport/StackTrace.cpp ${CMAKE_SOURCE_DIR}/src/OSSupport/TCPLinkImpl.cpp + ${CMAKE_SOURCE_DIR}/src/OSSupport/WinStackWalker.cpp ${CMAKE_SOURCE_DIR}/src/mbedTLS++/CtrDrbgContext.cpp ${CMAKE_SOURCE_DIR}/src/mbedTLS++/CryptoKey.cpp ${CMAKE_SOURCE_DIR}/src/mbedTLS++/EntropyContext.cpp @@ -39,8 +41,10 @@ set (Network_HDRS ${CMAKE_SOURCE_DIR}/src/OSSupport/NetworkLookup.h ${CMAKE_SOURCE_DIR}/src/OSSupport/NetworkSingleton.h ${CMAKE_SOURCE_DIR}/src/OSSupport/ServerHandleImpl.h + ${CMAKE_SOURCE_DIR}/src/OSSupport/StackTrace.h ${CMAKE_SOURCE_DIR}/src/OSSupport/TCPLinkImpl.h ${CMAKE_SOURCE_DIR}/src/OSSupport/Queue.h + ${CMAKE_SOURCE_DIR}/src/OSSupport/WinStackWalker.h ${CMAKE_SOURCE_DIR}/src/mbedTLS++/CtrDrbgContext.h ${CMAKE_SOURCE_DIR}/src/mbedTLS++/CryptoKey.h ${CMAKE_SOURCE_DIR}/src/mbedTLS++/EntropyContext.h |