1
0

Deal with covered switches consistently (#4161)

* Fixes a number of "<function>: 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()
This commit is contained in:
peterbell10 2018-02-04 23:07:12 +00:00 committed by GitHub
parent 2df14a0496
commit d3c1c626f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
40 changed files with 267 additions and 392 deletions

View File

@ -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);
}

View File

@ -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:
switch (a_Strategy)
{
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::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
);
break;
} // case msFillAir
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
);
break;
} // case msImprint
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
);
break;
} // case msLake
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
);
break;
} // case msSpongePrint
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
);
break;
} // case msDifference
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
);
break;
} // case msSimpleCompare
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
);
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)
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())
{

View File

@ -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");
}

View File

@ -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)

View File

@ -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

View File

@ -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)

View File

@ -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)

View File

@ -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

View File

@ -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");
}
} ;

View File

@ -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)

View File

@ -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)

View File

@ -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");
}

View File

@ -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");
}

View File

@ -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");
}

View File

@ -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");
}

View File

@ -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");
}

View File

@ -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

View File

@ -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(""))

View File

@ -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");
}

View File

@ -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) &&

View File

@ -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");
}

View File

@ -274,6 +274,7 @@ int cStructGenTrees::GetNumTrees(
return 0;
}
}
UNREACHABLE("Unsupported biome");
};
int NumTrees = 0;

View File

@ -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)

View File

@ -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");
}

View File

@ -27,6 +27,7 @@ public:
case dlaBreakBlock: return 1;
case dlaBreakBlockInstant: return 0;
}
UNREACHABLE("Unsupported durability loss action");
}

View File

@ -75,5 +75,6 @@ public:
case dlaBreakBlock: return 0;
case dlaBreakBlockInstant: return 0;
}
UNREACHABLE("Unsupported durability loss action");
}
} ;

View File

@ -26,6 +26,7 @@ public:
case dlaBreakBlock: return 1;
case dlaBreakBlockInstant: return 0;
}
UNREACHABLE("Unsupported durability loss action");
}

View File

@ -69,6 +69,7 @@ public:
case dlaBreakBlock: return 0;
case dlaBreakBlockInstant: return 1;
}
UNREACHABLE("Unsupported durability loss action");
}

View File

@ -31,6 +31,7 @@ public:
case dlaBreakBlock: return 1;
case dlaBreakBlockInstant: return 0;
}
UNREACHABLE("Unsupported durability loss action");
}

View File

@ -50,6 +50,7 @@ public:
case dlaBreakBlock: return 2;
case dlaBreakBlockInstant: return 0;
}
UNREACHABLE("Unsupported durability loss action");
}

View File

@ -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");
}

View File

@ -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");
}

View File

@ -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");
}

View File

@ -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");
}

View File

@ -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");
}

View File

@ -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";
}
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wcovered-switch-default"
#pragma clang diagnostic ignored "-Wunreachable-code"
#endif
default:
{
return "<unrecognized error>";
}
#ifdef __clang__
#pragma clang diagnostic pop
#endif
}
UNREACHABLE("Unsupported nbt parse error");
}
} // namespace (anonymous)
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

View File

@ -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
{

View File

@ -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);

View File

@ -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
)

View File

@ -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