Recently, I had a bug where, we changed the function from
void update_waypoint_heading(const double new_observation, waypoint)
{
// ....
waypoint.heading = default_heading_deg * waypoint.some_magic_number
}
// Call the function and the function will calculate new heading and mutate heading in waypoint
update_waypoint_heading(new_observation, waypoint);
to
double update_waypoint_heading(const double new_observation, waypoint)
{
// ....
return default_heading_deg * waypoint.some_magic_number
}
// Here the caller is supposed to be responsible for mutation
waypoint.heading = update_waypoint_heading(new_observation, waypoint);
We had a bug where we changed the function but did not change the caller. So we ended with
update_waypoint_heading(new_observation, waypoint);
Where update_waypoint_heading
started to return the new heading. But it never got set to the waypoint. This was also perfectly legal for the compiler.
Is it possible to declare a parameter as mutant
(like the opposite of const
), where it will throw a compiler error if it does not get mutated. So that I can catch these cases at compile time