C++ Logo


Advanced search

Attribute: [[nostrict_enum]]

From: Desmond Gold Bongcawel <desmondbongcawel922_at_[hidden]>
Date: Tue, 14 Dec 2021 20:30:56 +0800
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]]`


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)]].

Received on 2021-12-14 06:31:12