summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPatric Stout <truebrain@openttd.org>2021-04-01 11:16:19 +0200
committerGitHub <noreply@github.com>2021-04-01 11:16:19 +0200
commitfece1c57cab1d148e15775f3e10ba474dcfc1360 (patch)
tree864829048f995a13c2ada0a6f731404a7de0bab7 /src
parent9eb6c78a0245317f8dc68ad1034b66019e1bf14f (diff)
downloadopenttd-fece1c57cab1d148e15775f3e10ba474dcfc1360.tar.xz
Codechange: Suppress warnings when asserts are disabled (#8917)
Diffstat (limited to 'src')
-rw-r--r--src/autoreplace_cmd.cpp2
-rw-r--r--src/driver.cpp5
-rw-r--r--src/engine.cpp4
-rw-r--r--src/industry_cmd.cpp1
-rw-r--r--src/misc/hashtable.hpp1
-rw-r--r--src/object_gui.cpp3
-rw-r--r--src/spritecache.cpp2
-rw-r--r--src/tgp.cpp4
-rw-r--r--src/town_cmd.cpp5
-rw-r--r--src/townname.cpp2
-rw-r--r--src/tunnelbridge_cmd.cpp1
-rw-r--r--src/vehicle.cpp3
-rw-r--r--src/vehiclelist.cpp1
-rw-r--r--src/widget.cpp4
14 files changed, 31 insertions, 7 deletions
diff --git a/src/autoreplace_cmd.cpp b/src/autoreplace_cmd.cpp
index b72338021..fe86917c7 100644
--- a/src/autoreplace_cmd.cpp
+++ b/src/autoreplace_cmd.cpp
@@ -597,6 +597,7 @@ static CommandCost ReplaceChain(Vehicle **chain, DoCommandFlag flags, bool wagon
/* Sell wagon */
CommandCost ret = DoCommand(0, wagon->index, 0, DC_EXEC, GetCmdSellVeh(wagon));
+ (void)ret; // assert only
assert(ret.Succeeded());
new_vehs[i] = nullptr;
@@ -652,6 +653,7 @@ static CommandCost ReplaceChain(Vehicle **chain, DoCommandFlag flags, bool wagon
for (int i = num_units - 1; i > 0; i--) {
CommandCost ret = CmdMoveVehicle(old_vehs[i], old_head, DC_EXEC | DC_AUTOREPLACE, false);
+ (void)ret; // assert only
assert(ret.Succeeded());
}
}
diff --git a/src/driver.cpp b/src/driver.cpp
index 42520648f..cfda1d3d3 100644
--- a/src/driver.cpp
+++ b/src/driver.cpp
@@ -221,8 +221,9 @@ DriverFactoryBase::DriverFactoryBase(Driver::Type type, int priority, const char
strecpy(buf, GetDriverTypeName(type), lastof(buf));
strecpy(buf + 5, name, lastof(buf));
- std::pair<Drivers::iterator, bool> P = GetDrivers().insert(Drivers::value_type(buf, this));
- assert(P.second);
+ Drivers &drivers = GetDrivers();
+ assert(drivers.find(buf) == drivers.end());
+ drivers.insert(Drivers::value_type(buf, this));
}
/**
diff --git a/src/engine.cpp b/src/engine.cpp
index a72de454b..596e87063 100644
--- a/src/engine.cpp
+++ b/src/engine.cpp
@@ -549,6 +549,7 @@ void SetupEngines()
* in any case, and we just cleaned the pool. */
assert(Engine::CanAllocateItem());
const Engine *e = new Engine(eid.type, eid.internal_id);
+ (void)e; // assert only
assert(e->index == index);
index++;
}
@@ -1003,8 +1004,7 @@ static void NewVehicleAvailable(Engine *e)
if (e->type == VEH_TRAIN) {
/* maybe make another rail type available */
- RailType railtype = e->u.rail.railtype;
- assert(railtype < RAILTYPE_END);
+ assert(e->u.rail.railtype < RAILTYPE_END);
for (Company *c : Company::Iterate()) c->avail_railtypes = AddDateIntroducedRailTypes(c->avail_railtypes | GetRailTypeInfo(e->u.rail.railtype)->introduces_railtypes, _date);
} else if (e->type == VEH_ROAD) {
/* maybe make another road type available */
diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp
index ca52d1351..37bbd915c 100644
--- a/src/industry_cmd.cpp
+++ b/src/industry_cmd.cpp
@@ -2140,6 +2140,7 @@ static Industry *CreateNewIndustry(TileIndex tile, IndustryType type, IndustryAv
Industry *i = nullptr;
size_t layout_index = RandomRange((uint32)indspec->layouts.size());
CommandCost ret = CreateNewIndustryHelper(tile, type, DC_EXEC, indspec, layout_index, seed, GB(seed2, 0, 16), OWNER_NONE, creation_type, &i);
+ (void)ret; // assert only
assert(i != nullptr || ret.Failed());
return i;
}
diff --git a/src/misc/hashtable.hpp b/src/misc/hashtable.hpp
index ee6b88234..c7bb600da 100644
--- a/src/misc/hashtable.hpp
+++ b/src/misc/hashtable.hpp
@@ -240,6 +240,7 @@ public:
void Pop(Titem_ &item)
{
bool ret = TryPop(item);
+ (void)ret; // assert only
assert(ret);
}
diff --git a/src/object_gui.cpp b/src/object_gui.cpp
index b52c22b6e..7fab0b194 100644
--- a/src/object_gui.cpp
+++ b/src/object_gui.cpp
@@ -194,8 +194,7 @@ public:
} else {
this->SelectFirstAvailableObject(true);
}
- ObjectClass *objclass = ObjectClass::Get(_selected_object_class);
- assert(objclass->GetUISpecCount() > 0); // object GUI should be disabled elsewise
+ assert(ObjectClass::Get(_selected_object_class)->GetUISpecCount() > 0); // object GUI should be disabled elsewise
}
void SetStringParameters(int widget) const override
diff --git a/src/spritecache.cpp b/src/spritecache.cpp
index 8460f33ed..1c7cc6f78 100644
--- a/src/spritecache.cpp
+++ b/src/spritecache.cpp
@@ -229,7 +229,9 @@ static void ResizeSpriteOut(SpriteLoader::Sprite *sprite, ZoomLevel zoom)
SpriteLoader::CommonPixel *dst = sprite[zoom].data;
const SpriteLoader::CommonPixel *src = sprite[zoom - 1].data;
+#ifndef NDEBUG
const SpriteLoader::CommonPixel *src_end = src + sprite[zoom - 1].height * sprite[zoom - 1].width;
+#endif
for (uint y = 0; y < sprite[zoom].height; y++) {
const SpriteLoader::CommonPixel *src_ln = src + sprite[zoom - 1].width;
diff --git a/src/tgp.cpp b/src/tgp.cpp
index d86617ee2..39fda6e6b 100644
--- a/src/tgp.cpp
+++ b/src/tgp.cpp
@@ -658,7 +658,9 @@ static void HeightMapCurves(uint level)
for (uint t = 0; t < lengthof(curve_maps); t++) {
if (!HasBit(corner_bits, t)) continue;
+#ifndef NDEBUG
bool found = false;
+#endif
const control_point_t *cm = curve_maps[t].list;
for (uint i = 0; i < curve_maps[t].length - 1; i++) {
const control_point_t &p1 = cm[i];
@@ -666,7 +668,9 @@ static void HeightMapCurves(uint level)
if (*h >= p1.x && *h < p2.x) {
ht[t] = p1.y + (*h - p1.x) * (p2.y - p1.y) / (p2.x - p1.x);
+#ifndef NDEBUG
found = true;
+#endif
break;
}
}
diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp
index a37c36ed7..023063c1f 100644
--- a/src/town_cmd.cpp
+++ b/src/town_cmd.cpp
@@ -107,10 +107,12 @@ Town::~Town()
DeleteWindowById(WC_TOWN_VIEW, this->index);
/* Check no industry is related to us. */
+#ifndef NDEBUG
for (const Industry *i : Industry::Iterate()) assert(i->town != this);
/* ... and no object is related to us. */
for (const Object *o : Object::Iterate()) assert(o->town != this);
+#endif
/* Check no tile is related to us. */
for (TileIndex tile = 0; tile < MapSize(); ++tile) {
@@ -2176,6 +2178,7 @@ static Town *CreateRandomTown(uint attempts, uint32 townnameparts, TownSize size
Backup<CompanyID> cur_company(_current_company, OWNER_TOWN, FILE_LINE);
CommandCost rc = DoCommand(t->xy, t->index, 0, DC_EXEC, CMD_DELETE_TOWN);
+ (void)rc; // assert only
cur_company.Restore();
assert(rc.Succeeded());
@@ -2277,7 +2280,7 @@ HouseZonesBits GetTownRadiusGroup(const Town *t, TileIndex tile)
static inline void ClearMakeHouseTile(TileIndex tile, Town *t, byte counter, byte stage, HouseID type, byte random_bits)
{
CommandCost cc = DoCommand(tile, 0, 0, DC_EXEC | DC_AUTO | DC_NO_WATER, CMD_LANDSCAPE_CLEAR);
-
+ (void)cc; // assert only
assert(cc.Succeeded());
IncreaseBuildingCount(t, type);
diff --git a/src/townname.cpp b/src/townname.cpp
index e7999f9a5..082c40f75 100644
--- a/src/townname.cpp
+++ b/src/townname.cpp
@@ -600,7 +600,9 @@ static char *MakeCzechTownName(char *buf, const char *last, uint32 seed)
return strecpy(buf, _name_czech_real[SeedModChance(4, lengthof(_name_czech_real), seed)], last);
}
+#ifndef NDEBUG
const char *orig = buf;
+#endif
/* Probability of prefixes/suffixes
* 0..11 prefix, 12..13 prefix+suffix, 14..17 suffix, 18..31 nothing */
diff --git a/src/tunnelbridge_cmd.cpp b/src/tunnelbridge_cmd.cpp
index e71440fc2..2f76dbcef 100644
--- a/src/tunnelbridge_cmd.cpp
+++ b/src/tunnelbridge_cmd.cpp
@@ -1847,6 +1847,7 @@ static void ChangeTileOwner_TunnelBridge(TileIndex tile, Owner old_owner, Owner
/* Since all of our vehicles have been removed, it is safe to remove the rail
* bridge / tunnel. */
CommandCost ret = DoCommand(tile, 0, 0, DC_EXEC | DC_BANKRUPT, CMD_LANDSCAPE_CLEAR);
+ (void)ret; // assert only
assert(ret.Succeeded());
} else {
/* In any other case, we can safely reassign the ownership to OWNER_NONE. */
diff --git a/src/vehicle.cpp b/src/vehicle.cpp
index 3f10bc42a..8ffaea408 100644
--- a/src/vehicle.cpp
+++ b/src/vehicle.cpp
@@ -953,7 +953,10 @@ void CallVehicleTicks()
PerformanceAccumulator::Reset(PFE_GL_AIRCRAFT);
for (Vehicle *v : Vehicle::Iterate()) {
+#ifndef NDEBUG
size_t vehicle_index = v->index;
+#endif
+
/* Vehicle could be deleted in this tick */
if (!v->Tick()) {
assert(Vehicle::Get(vehicle_index) == nullptr);
diff --git a/src/vehiclelist.cpp b/src/vehiclelist.cpp
index a574d9b81..ea34c443c 100644
--- a/src/vehiclelist.cpp
+++ b/src/vehiclelist.cpp
@@ -54,6 +54,7 @@ bool VehicleListIdentifier::UnpackIfValid(uint32 data)
{
VehicleListIdentifier result;
bool ret = result.UnpackIfValid(data);
+ (void)ret; // assert only
assert(ret);
return result;
}
diff --git a/src/widget.cpp b/src/widget.cpp
index 2260d463f..b06562108 100644
--- a/src/widget.cpp
+++ b/src/widget.cpp
@@ -1156,7 +1156,9 @@ void NWidgetHorizontal::SetupSmallestSize(Window *w, bool init_array)
this->smallest_y = std::max(this->smallest_y, child_wid->smallest_y + child_wid->padding_top + child_wid->padding_bottom);
}
/* 1b. Make the container higher if needed to accommodate all children nicely. */
+#ifndef NDEBUG
uint max_smallest = this->smallest_y + 3 * max_vert_fill; // Upper limit to computing smallest height.
+#endif
uint cur_height = this->smallest_y;
for (;;) {
for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {
@@ -1321,7 +1323,9 @@ void NWidgetVertical::SetupSmallestSize(Window *w, bool init_array)
this->smallest_x = std::max(this->smallest_x, child_wid->smallest_x + child_wid->padding_left + child_wid->padding_right);
}
/* 1b. Make the container wider if needed to accommodate all children nicely. */
+#ifndef NDEBUG
uint max_smallest = this->smallest_x + 3 * max_hor_fill; // Upper limit to computing smallest height.
+#endif
uint cur_width = this->smallest_x;
for (;;) {
for (NWidgetBase *child_wid = this->head; child_wid != nullptr; child_wid = child_wid->next) {