C++ Logo

std-proposals

Advanced search

Re: Attribute: [[nostrict_enum]]

From: Pavel Vazharov <freakpv_at_[hidden]>
Date: Tue, 14 Dec 2021 14:38:25 +0200
I think adding `default: break;` to the switch will silence the warnings in
the first case.

On Tue, Dec 14, 2021 at 2:31 PM Desmond Gold Bongcawel via Std-Proposals <
std-proposals_at_[hidden]> wrote:

> I have been annoyed by some compiler warnings complaining that some
> enumerators are not included as case labels inside a switch statement, and
> another one that using enumerators with bitwise operators such as `read |
> binary`, the compiler will also trigger a warning. For GCC, it is
> specifically "-Wswitch"
>
> Therefore, I will propose an idea that solves these irritating warnings
> using an attribute `[[strict_enum]]`
>
> Syntax:
> [[nostrict_enum]]
>
> This can be applied to switch statements:
> ```
> switch (mode) [[nostrict_enum]] { /* ... */ }
> ```
>
> Then the previous code will be compiled omitting specific warning.
>
> The alternative syntax would be:
> [[strict_enum(<boolean-literal>)]] where it could only be:
> [[strict_enum(true)]] and [[strict_enum(false)]].
> --
> Std-Proposals mailing list
> Std-Proposals_at_[hidden]
> https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals
>

Received on 2021-12-14 06:38:37