The Issue With Default in Switch Statements with Enums
July 5, 2025
Reading the coding standards at a company I recently joined revealed to me the issue with default label within the switch statement and why it’s prohibitted when its being
used to enumerate through an enum
. default
label is convenient to handle any edge cases and it’s often used to handle errors. However, when working with enums, it is often
the case that the prpogrammer intends to handle all possible values in the enum. To catch this mishap, programmers would enable -Wswitch
or -Werror=switch
to their compiler.
For instance, let’s suppose I have an enum named Suit to represent the different suits in a deck of cards.