summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTiger Wang <ziwei.tiger@outlook.com>2021-02-20 17:24:13 +0100
committerTiger Wang <ziwei.tiger@outlook.com>2021-02-20 18:46:02 +0100
commit81e299f00ce3df587166ccc94f5997555cce5210 (patch)
treed5954c7f5756b67b2c6c1f7c6f2b635f5337eef2
parentClang 7? (diff)
downloadcuberite-81e299f00ce3df587166ccc94f5997555cce5210.tar
cuberite-81e299f00ce3df587166ccc94f5997555cce5210.tar.gz
cuberite-81e299f00ce3df587166ccc94f5997555cce5210.tar.bz2
cuberite-81e299f00ce3df587166ccc94f5997555cce5210.tar.lz
cuberite-81e299f00ce3df587166ccc94f5997555cce5210.tar.xz
cuberite-81e299f00ce3df587166ccc94f5997555cce5210.tar.zst
cuberite-81e299f00ce3df587166ccc94f5997555cce5210.zip
Diffstat (limited to '')
-rw-r--r--src/BlockEntities/NoteEntity.cpp1
-rw-r--r--src/Blocks/BlockButton.h8
-rw-r--r--src/Blocks/BlockCocoaPod.h3
-rw-r--r--src/Blocks/BlockHandler.cpp1
-rw-r--r--src/Blocks/BlockSideways.h3
-rw-r--r--src/Blocks/BlockTripwireHook.h1
-rw-r--r--src/Defines.cpp1
-rw-r--r--src/Generating/StructGen.cpp3
-rw-r--r--src/Globals.h12
-rw-r--r--src/MobCensus.cpp3
-rw-r--r--src/Protocol/ChunkDataSerializer.cpp1
-rw-r--r--src/Protocol/Protocol_1_10.cpp7
-rw-r--r--src/Protocol/Protocol_1_11.cpp7
-rw-r--r--src/Protocol/Protocol_1_12.cpp6
-rw-r--r--src/Protocol/Protocol_1_13.cpp10
-rw-r--r--src/Protocol/Protocol_1_8.cpp9
-rw-r--r--src/Protocol/Protocol_1_9.cpp5
-rw-r--r--src/WorldStorage/NamespaceSerializer.cpp2
18 files changed, 27 insertions, 56 deletions
diff --git a/src/BlockEntities/NoteEntity.cpp b/src/BlockEntities/NoteEntity.cpp
index 3e9958892..419d084b2 100644
--- a/src/BlockEntities/NoteEntity.cpp
+++ b/src/BlockEntities/NoteEntity.cpp
@@ -318,6 +318,5 @@ float cNoteEntity::PitchFromNote(unsigned char a_Pitch)
case 23: return 1.887748625363387f;
case 24: return 2.0f;
}
-
UNREACHABLE("Converted unknown pitch value");
}
diff --git a/src/Blocks/BlockButton.h b/src/Blocks/BlockButton.h
index 062bd5057..985c1fff9 100644
--- a/src/Blocks/BlockButton.h
+++ b/src/Blocks/BlockButton.h
@@ -132,8 +132,7 @@ private:
case BLOCK_FACE_YM: return 0x0;
case BLOCK_FACE_NONE:
{
- ASSERT(!"Unhandled block face!");
- return 0x0;
+ break;
}
}
UNREACHABLE("Unsupported block face");
@@ -265,10 +264,9 @@ private:
case BLOCK_FACE_YP: return { 0.5, 0, 0.5 };
case BLOCK_FACE_NONE:
{
- ASSERT(!"Unhandled block face!");
- return { 0, 0, 0 };
+ break;
}
}
- UNREACHABLE(!"Unhandled block face!");
+ UNREACHABLE("Unhandled block face!");
}
} ;
diff --git a/src/Blocks/BlockCocoaPod.h b/src/Blocks/BlockCocoaPod.h
index d78164ea6..caff5c028 100644
--- a/src/Blocks/BlockCocoaPod.h
+++ b/src/Blocks/BlockCocoaPod.h
@@ -28,8 +28,7 @@ public:
case BLOCK_FACE_YM:
case BLOCK_FACE_YP:
{
- ASSERT(!"Unknown face");
- return 0;
+ break;
}
}
UNREACHABLE("Unsupported block face");
diff --git a/src/Blocks/BlockHandler.cpp b/src/Blocks/BlockHandler.cpp
index 0e1672ce8..71169ea7f 100644
--- a/src/Blocks/BlockHandler.cpp
+++ b/src/Blocks/BlockHandler.cpp
@@ -936,6 +936,5 @@ const cBlockHandler & cBlockHandler::For(BLOCKTYPE a_BlockType)
case E_BLOCK_NUMBER_OF_TYPES:
case E_BLOCK_UNFINISHED: return BlockAirHandler;
}
-
UNREACHABLE("Getting handler for unexpected block type");
}
diff --git a/src/Blocks/BlockSideways.h b/src/Blocks/BlockSideways.h
index a8eb52fc6..a6e035601 100644
--- a/src/Blocks/BlockSideways.h
+++ b/src/Blocks/BlockSideways.h
@@ -74,8 +74,7 @@ private:
case BLOCK_FACE_NONE:
{
- ASSERT(!"Unhandled block face!");
- return a_Meta | 0xC; // No idea, give a special meta
+ break;
}
}
UNREACHABLE("Unsupported block face");
diff --git a/src/Blocks/BlockTripwireHook.h b/src/Blocks/BlockTripwireHook.h
index 0d46da437..0d58bb084 100644
--- a/src/Blocks/BlockTripwireHook.h
+++ b/src/Blocks/BlockTripwireHook.h
@@ -70,7 +70,6 @@ private:
return false;
}
}
-
UNREACHABLE("Unsupported block face");
}
diff --git a/src/Defines.cpp b/src/Defines.cpp
index 7e4274bd5..4adbc1c5c 100644
--- a/src/Defines.cpp
+++ b/src/Defines.cpp
@@ -41,7 +41,6 @@ const char * ClickActionToString(int a_ClickAction)
case caRightPaintEnd: return "caRightPaintEnd";
case caMiddlePaintEnd: return "caMiddlePaintEnd";
case caDblClick: return "caDblClick";
-
case caUnknown: return "caUnknown";
}
UNREACHABLE("Unknown click action");
diff --git a/src/Generating/StructGen.cpp b/src/Generating/StructGen.cpp
index d9620b19d..9fa413e2d 100644
--- a/src/Generating/StructGen.cpp
+++ b/src/Generating/StructGen.cpp
@@ -287,8 +287,7 @@ double cStructGenTrees::GetNumTrees(
case biVariant:
case biNumVariantBiomes:
{
- ASSERT(!"Invalid biome in cStructGenTrees::GetNumTrees");
- return 0.0;
+ break;
}
}
UNREACHABLE("Unsupported biome");
diff --git a/src/Globals.h b/src/Globals.h
index c081c5998..bc868b637 100644
--- a/src/Globals.h
+++ b/src/Globals.h
@@ -35,11 +35,15 @@
// The CRT has a definition for this operator new that stores the debugging info for leak-finding later.
#endif
+ #define UNREACHABLE_INTRINSIC __assume(false)
+
#elif defined(__GNUC__)
// TODO: Can GCC explicitly mark classes as abstract (no instances can be created)?
#define abstract
+ #define UNREACHABLE_INTRINSIC __builtin_unreachable()
+
#else
#error "You are using an unsupported compiler, you might need to #define some stuff here for your compiler"
@@ -271,8 +275,12 @@ template class SizeChecker<UInt8, 1>;
#endif // else TEST_GLOBALS
-/** 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__); std::abort(); } while (false)
+// Use to mark code that should be impossible to reach.
+#ifdef NDEBUG
+ #define UNREACHABLE(x) UNREACHABLE_INTRINSIC
+#else
+ #define UNREACHABLE(x) ( FLOGERROR("Hit unreachable code: {0}, file {1}, line {2}", #x, __FILE__, __LINE__), std::abort(), 0)
+#endif
diff --git a/src/MobCensus.cpp b/src/MobCensus.cpp
index 1069a964e..8f5fdde75 100644
--- a/src/MobCensus.cpp
+++ b/src/MobCensus.cpp
@@ -41,8 +41,7 @@ int cMobCensus::GetCapMultiplier(cMonster::eFamily a_MobFamily)
case cMonster::mfNoSpawn:
case cMonster::mfUnhandled:
{
- ASSERT(!"Unhandled mob family");
- return -1;
+ break;
}
}
UNREACHABLE("Unsupported mob family");
diff --git a/src/Protocol/ChunkDataSerializer.cpp b/src/Protocol/ChunkDataSerializer.cpp
index 2c45eea58..ec7fa6648 100644
--- a/src/Protocol/ChunkDataSerializer.cpp
+++ b/src/Protocol/ChunkDataSerializer.cpp
@@ -118,7 +118,6 @@ void cChunkDataSerializer::SendToClients(const int a_ChunkX, const int a_ChunkZ,
continue;
}
}
-
UNREACHABLE("Unknown chunk data serialization version");
}
diff --git a/src/Protocol/Protocol_1_10.cpp b/src/Protocol/Protocol_1_10.cpp
index b3a3205d5..89bc3f010 100644
--- a/src/Protocol/Protocol_1_10.cpp
+++ b/src/Protocol/Protocol_1_10.cpp
@@ -1053,7 +1053,7 @@ void cProtocol_1_10_0::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_
case mtZombieHorse:
{
// Todo: Mobs not added yet. Grouped ones have the same metadata
- UNREACHABLE("cProtocol_1_10::WriteMobMetadata: received unimplemented type");
+ ASSERT(!"cProtocol_1_10::WriteMobMetadata: received unimplemented type");
break;
}
@@ -1072,10 +1072,7 @@ void cProtocol_1_10_0::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_
// Entities without additional metadata
break;
}
- case mtInvalidType:
- {
- break;
- }
+
default: UNREACHABLE("cProtocol_1_10::WriteMobMetadata: received mob of invalid type");
} // switch (a_Mob.GetType())
}
diff --git a/src/Protocol/Protocol_1_11.cpp b/src/Protocol/Protocol_1_11.cpp
index ff0c34223..c8ba78e62 100644
--- a/src/Protocol/Protocol_1_11.cpp
+++ b/src/Protocol/Protocol_1_11.cpp
@@ -1241,7 +1241,7 @@ void cProtocol_1_11_0::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_
case mtVindicator:
{
// Todo: Mobs not added yet. Grouped ones have the same metadata
- UNREACHABLE("cProtocol_1_11::WriteMobMetadata: received unimplemented type");
+ ASSERT(!"cProtocol_1_11::WriteMobMetadata: received unimplemented type");
break;
}
@@ -1260,10 +1260,7 @@ void cProtocol_1_11_0::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_
// Mobs without additional metadata
break;
}
- case mtInvalidType:
- {
- break;
- }
+
default: UNREACHABLE("cProtocol_1_11::WriteMobMetadata: received mob of invalid type");
} // switch (a_Mob.GetType())
}
diff --git a/src/Protocol/Protocol_1_12.cpp b/src/Protocol/Protocol_1_12.cpp
index e4ce9a942..81f81dc1c 100644
--- a/src/Protocol/Protocol_1_12.cpp
+++ b/src/Protocol/Protocol_1_12.cpp
@@ -957,7 +957,7 @@ void cProtocol_1_12::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_Mo
case mtVindicator:
{
// Todo: Mobs not added yet. Grouped ones have the same metadata
- UNREACHABLE("cProtocol_1_12::WriteMobMetadata: received unimplemented type");
+ ASSERT(!"cProtocol_1_12::WriteMobMetadata: received unimplemented type");
break;
}
@@ -970,10 +970,6 @@ void cProtocol_1_12::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_Mo
break;
}
- case mtInvalidType:
- {
- break;
- }
default: UNREACHABLE("cProtocol_1_12::WriteMobMetadata: received mob of invalid type");
} // switch (a_Mob.GetType())
}
diff --git a/src/Protocol/Protocol_1_13.cpp b/src/Protocol/Protocol_1_13.cpp
index dbfd51d59..afb0a9cc9 100644
--- a/src/Protocol/Protocol_1_13.cpp
+++ b/src/Protocol/Protocol_1_13.cpp
@@ -463,7 +463,6 @@ UInt32 cProtocol_1_13::GetProtocolMobType(eMonsterType a_MobType)
case mtZombiePigman: return 53;
case mtZombieHorse: return 88;
case mtZombieVillager: return 89;
-
default: return 0;
}
UNREACHABLE("Unsupported mob type");
@@ -599,7 +598,6 @@ UInt8 cProtocol_1_13::GetEntityMetadataID(EntityMetadata a_Metadata)
case EntityMetadata::AbstractSkeletonArmsSwinging:
case EntityMetadata::ZombieUnusedWasType: break;
}
-
UNREACHABLE("Retrieved invalid metadata for protocol");
}
@@ -631,7 +629,6 @@ UInt8 cProtocol_1_13::GetEntityMetadataID(EntityMetadataType a_FieldType)
case EntityMetadataType::OptVarInt: return 17;
case EntityMetadataType::Pose: return 18;
}
-
UNREACHABLE("Translated invalid metadata type for protocol");
}
@@ -1307,10 +1304,9 @@ void cProtocol_1_13::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_Mo
case mtVindicator:
case mtHusk:
-
{
// Todo: Mobs not added yet. Grouped ones have the same metadata
- UNREACHABLE("cProtocol_1_13::WriteMobMetadata: received unimplemented type");
+ ASSERT(!"cProtocol_1_13::WriteMobMetadata: received unimplemented type");
break;
}
@@ -1331,10 +1327,6 @@ void cProtocol_1_13::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_Mo
break;
}
- case mtInvalidType:
- {
- break;
- }
default: UNREACHABLE("cProtocol_1_13::WriteMobMetadata: received mob of invalid type");
} // switch (a_Mob.GetType())
}
diff --git a/src/Protocol/Protocol_1_8.cpp b/src/Protocol/Protocol_1_8.cpp
index 003fc75e2..91c132c8b 100644
--- a/src/Protocol/Protocol_1_8.cpp
+++ b/src/Protocol/Protocol_1_8.cpp
@@ -3848,7 +3848,7 @@ void cProtocol_1_8_0::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_M
case mtZombieHorse:
{
// Todo: Mobs not added yet. Grouped ones have the same metadata
- UNREACHABLE("cProtocol_1_8::WriteMobMetadata: received unimplemented type");
+ ASSERT(!"cProtocol_1_8::WriteMobMetadata: received unimplemented type");
break;
}
@@ -3865,10 +3865,7 @@ void cProtocol_1_8_0::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_M
// Allowed mobs without additional metadata
break;
}
- case mtInvalidType:
- {
- break;
- }
+
default: UNREACHABLE("cProtocol_1_8::WriteMobMetadata: received mob of invalid type");
} // switch (a_Mob.GetType())
}
@@ -4029,7 +4026,7 @@ UInt8 cProtocol_1_8_0::GetProtocolEntityType(const cEntity & a_Entity)
case Type::etPlayer:
case Type::etMonster:
case Type::etExpOrb:
- case Type::etPainting: UNREACHABLE("Tried to spawn an unhandled entity");
+ case Type::etPainting: break;
}
UNREACHABLE("Unhandled entity kind");
}
diff --git a/src/Protocol/Protocol_1_9.cpp b/src/Protocol/Protocol_1_9.cpp
index e2396ce0e..5506aec1a 100644
--- a/src/Protocol/Protocol_1_9.cpp
+++ b/src/Protocol/Protocol_1_9.cpp
@@ -2150,7 +2150,7 @@ void cProtocol_1_9_0::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_M
case mtShulker:
{
// Todo: Mobs not added yet. Grouped ones have the same metadata
- UNREACHABLE("cProtocol_1_9::WriteMobMetadata: received unimplemented type");
+ ASSERT(!"cProtocol_1_9::WriteMobMetadata: received unimplemented type");
break;
}
@@ -2167,10 +2167,7 @@ void cProtocol_1_9_0::WriteMobMetadata(cPacketizer & a_Pkt, const cMonster & a_M
// Entities without additional metadata
break;
}
- case mtInvalidType:
- {
- }
default: UNREACHABLE("cProtocol_1_9::WriteMobMetadata: received mob of invalid type");
} // switch (a_Mob.GetType())
}
diff --git a/src/WorldStorage/NamespaceSerializer.cpp b/src/WorldStorage/NamespaceSerializer.cpp
index 4d3d1a544..088714cd1 100644
--- a/src/WorldStorage/NamespaceSerializer.cpp
+++ b/src/WorldStorage/NamespaceSerializer.cpp
@@ -133,7 +133,6 @@ std::string_view NamespaceSerializer::From(const Statistic a_ID)
case Statistic::AchBreedCow: return "cuberite:achievement.breedCow";
case Statistic::AchDiamondsToYou: return "cuberite:achievement.diamondsToYou";
}
-
UNREACHABLE("Tried to save unhandled statistic");
}
@@ -216,7 +215,6 @@ std::string_view NamespaceSerializer::From(eMonsterType a_ID)
case mtZombieVillager: return "zombie_villager";
case mtInvalidType: break;
}
-
UNREACHABLE("Tried to save unknown monster type");
}