Andres Freund <and...@anarazel.de> writes: > It'd be nice if there were an easy way to write a switch() where the > compiler enforces that all enum values are checked, but still had the > possibility to have a 'default:' block for error checking... I can't > quite come up with a good approach to emulate that though.
Yeah, that would sure make things better. I was considering something like switch (enumvalue) { case A: ... case B: ... ... #ifndef USE_ASSERT_CHECKING default: elog(ERROR, ...); #endif } so that you get the runtime protection in production builds but not debug builds ... except that yes, you really want that protection in debug builds too. Maybe the #if could be on some other symbol so that the default: is normally enabled in all builds, but we have some lonely buildfarm animal that disables it and builds with -Werror to get our attention for omitted cases? regards, tom lane