Care and Feeding of Enum Flags

Maybe you've been looking at some C++ in the debugger not too long ago and happened across some enum flags on an object in your codebase. However, rather than a friendly display of the individual flags present, you just got an unfriendly hex value.


The problem is that your enum flags are not flags. You've probably got something like we had in the Unreal Engine 4 codebase. Someone innocently defined a flag of flags, in this example, PKG_InMemoryOnly. Probably as a time saver they defined this semantic non-unique flag to avoid bugs in the codebase by having a semantic definition of some common concept.

Hopefully the Visual Studio Team will improve the check to allow for semantic flags that perfectly overlap with some number of other flags at some point in the future.

To get around the problem it's pretty simple, just extract all your semantic flags and make them #defines thusly,

Resulting in the much friendlier,