[clang] [clang][Sema] Add -Wswitch-default warning option (PR #73077)

dong jianqiang via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 18 03:24:03 PST 2023


dongjianqiang2 wrote:

> ```
> enum class test
> {
>   err1,
>   err2,
>   ok
> };
> 
> int check_err (test v)
> {
>   switch (v)
>     {
>       case test::err1:
>         return 1;
>       case test::err2:
>         return 2;
>       case test::ok:
>         break;
>     }
>   return 0;
> }
> ```
> 
> report: main.cxx:40:3: error: 'switch' missing 'default' label [-Werror,-Wswitch-default]
> 
> how to solve for enum class? try to build libfmt project with fmt/include/fmt/format.h:3878:3: error: 'switch' missing 'default' label [-Werror,-Wswitch-default] and other errors

Hi, -Wswitch-default is a warning option on switch which don't have the default branch, the option is disabled by default, You can check whether -Wswitch-default is added in the build script.

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


More information about the cfe-commits mailing list