Defensive programming: Difference between revisions

Content deleted Content added
Tags: Mobile edit Mobile web edit Advanced mobile edit
m Remove incorrect code comments, compilers will not remove default sections even if all possible enum values are covered. Compilers are not allowed to do this due to enums having more bit patterns than they have named members. A compilable example can be found here https://godbolt.org/z/hnKv7h8as
Line 62:
}
return "black"; // To be handled as a dead traffic light.
// Warning: This last 'return' statement will be dropped by an optimizing
// compiler if all possible values of 'traffic_light_color' are listed in
// the previous 'switch' statement...
}
</syntaxhighlight>
Line 77 ⟶ 74:
}
assert(0); // Assert that this section is unreachable.
// Warning: This 'assert' function call will be dropped by an optimizing
// compiler if all possible values of 'traffic_light_color' are listed in
// the previous 'switch' statement...
}
</syntaxhighlight>