From d3c1c626f569e5aa58085425924cca45927b6199 Mon Sep 17 00:00:00 2001 From: peterbell10 Date: Sun, 4 Feb 2018 23:07:12 +0000 Subject: Deal with covered switches consistently (#4161) * Fixes a number of ": not all control paths return a value" warnings on MSVC. * Introduces the UNREACHABLE global macro and uses it instead of conditionally compiled switch defaults. * Move cNBTParseErrorCategory from FastNBT.h into FastNBT.cpp to prevent bad calls to message() --- src/Generating/MineShafts.cpp | 45 ++++++++++++++++++++----------------------- src/Generating/PiecePool.cpp | 25 +++++------------------- src/Generating/StructGen.cpp | 1 + 3 files changed, 27 insertions(+), 44 deletions(-) (limited to 'src/Generating') 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 ""; - #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; -- cgit v1.2.3