Changeset - r26018:e7110597313b
[Not reviewed]
master
0 1 0
Patric Stout - 3 years ago 2021-10-16 20:06:08
truebrain@openttd.org
Codechange: "set but not used" warning when disabling assert() (#9613)

DebugCheckSanity() is unused when asserts are disabled. While at it,
use WITH_ASSERT over NDEBUG, as that means we also run this code
during beta/RC.
1 file changed with 3 insertions and 1 deletions:
0 comments (0 inline, 0 general)
src/order_cmd.cpp
Show inline comments
 
@@ -600,24 +600,25 @@ int OrderList::GetPositionInSharedOrderL
 
 * @return whether all orders have a filled timetable.
 
 */
 
bool OrderList::IsCompleteTimetable() const
 
{
 
	for (Order *o = this->first; o != nullptr; o = o->next) {
 
		/* Implicit orders are, by definition, not timetabled. */
 
		if (o->IsType(OT_IMPLICIT)) continue;
 
		if (!o->IsCompletelyTimetabled()) return false;
 
	}
 
	return true;
 
}
 

	
 
#ifdef WITH_ASSERT
 
/**
 
 * Checks for internal consistency of order list. Triggers assertion if something is wrong.
 
 */
 
void OrderList::DebugCheckSanity() const
 
{
 
	VehicleOrderID check_num_orders = 0;
 
	VehicleOrderID check_num_manual_orders = 0;
 
	uint check_num_vehicles = 0;
 
	Ticks check_timetable_duration = 0;
 
	Ticks check_total_duration = 0;
 

	
 
	Debug(misc, 6, "Checking OrderList {} for sanity...", this->index);
 
@@ -633,24 +634,25 @@ void OrderList::DebugCheckSanity() const
 
	assert(this->timetable_duration == check_timetable_duration);
 
	assert(this->total_duration == check_total_duration);
 

	
 
	for (const Vehicle *v = this->first_shared; v != nullptr; v = v->NextShared()) {
 
		++check_num_vehicles;
 
		assert(v->orders.list == this);
 
	}
 
	assert(this->num_vehicles == check_num_vehicles);
 
	Debug(misc, 6, "... detected {} orders ({} manual), {} vehicles, {} timetabled, {} total",
 
			(uint)this->num_orders, (uint)this->num_manual_orders,
 
			this->num_vehicles, this->timetable_duration, this->total_duration);
 
}
 
#endif
 

	
 
/**
 
 * Checks whether the order goes to a station or not, i.e. whether the
 
 * destination is a station
 
 * @param v the vehicle to check for
 
 * @param o the order to check
 
 * @return true if the destination is a station
 
 */
 
static inline bool OrderGoesToStation(const Vehicle *v, const Order *o)
 
{
 
	return o->IsType(OT_GOTO_STATION) ||
 
			(v->type == VEH_AIRCRAFT && o->IsType(OT_GOTO_DEPOT) && !(o->GetDepotActionType() & ODATFB_NEAREST_DEPOT));
 
@@ -1773,25 +1775,25 @@ void CheckOrders(const Vehicle *v)
 
		/* Check if the last and the first order are the same */
 
		if (v->GetNumOrders() > 1) {
 
			const Order *last = v->GetLastOrder();
 

	
 
			if (v->orders.list->GetFirstOrder()->Equals(*last)) {
 
				message = STR_NEWS_VEHICLE_HAS_DUPLICATE_ENTRY;
 
			}
 
		}
 

	
 
		/* Do we only have 1 station in our order list? */
 
		if (n_st < 2 && message == INVALID_STRING_ID) message = STR_NEWS_VEHICLE_HAS_TOO_FEW_ORDERS;
 

	
 
#ifndef NDEBUG
 
#ifdef WITH_ASSERT
 
		if (v->orders.list != nullptr) v->orders.list->DebugCheckSanity();
 
#endif
 

	
 
		/* We don't have a problem */
 
		if (message == INVALID_STRING_ID) return;
 

	
 
		SetDParam(0, v->index);
 
		AddVehicleAdviceNewsItem(message, v->index);
 
	}
 
}
 

	
 
/**
0 comments (0 inline, 0 general)