[clang] [Sema] Warn about omitting deprecated enumerator in switch (PR #138562)

Reid Kleckner via cfe-commits cfe-commits at lists.llvm.org
Tue May 20 13:10:15 PDT 2025


rnk wrote:

> I think silencing the warning is better than suggesting a default case, which may not be considered good practice.

I'm not sure, I think our perspectives as compiler people might be a bit off base. We're always forming closed algebraic sum types, like variants, AST nodes, that kind of thing. I think normal programs dealing with untrusted input coming from a file or over the wire typically need to be more conservative, and pushing users towards adding a `default` case or code to the fallthrough block without explicitly mentioning the deprecated enumerator might be the best outcome. Consider that -Wcovered-switch-default is not part of -Wall/-Wextra: https://godbolt.org/z/PrjqqxKrP

> That code will continue to work great right up until the enumerator is removed.

To Aaron's point about deprecation being a tool for removal, if the goal of deprecation is to remove the enumerator, then we *do* want folks to use `default`/fallthrough code patterns that don't explicitly mention the enum.


https://github.com/llvm/llvm-project/pull/138562


More information about the cfe-commits mailing list