5

The project I work on have things like the following:

enum SomeType {
    value_100     = 100,
    reserved_101  = 101,
    value_102     = 102
};

The presence of these 'reserved' identifiers, is not something the powers to be are willing to change.

I would like to adorn them somehow, something similar to [[maybe_unused]], so I can turn on -Werror=switch

This is a huge (and old) codebase, refactor to not use switches would be a major undertaking, not something on the table right now.

Is there some way to selectively silence warnings regarding unhandled enumeration values in gcc? Note that I still want the warnings for enumeration values not so adorned. Using a gcc extension would be ok.

Toby Speight
  • 27,591
  • 48
  • 66
  • 103
sp2danny
  • 7,488
  • 3
  • 31
  • 53
  • Probably a pragma. Have you tried the docs? Or search? https://stackoverflow.com/questions/3378560/how-to-disable-gcc-warnings-for-a-few-lines-of-code – Kenny Ostrom Mar 05 '19 at 14:09
  • Please specify if you want a global option or it's ok to do minimal modification of switch-cases in question. – yugr Apr 28 '19 at 15:09
  • @yugr Could a modification of the switch-cases work? – sp2danny May 03 '19 at 11:24
  • @sp2danny Well, you could just define `IGNORE_DEFAULTS` macro which would contain `case reserved_1: ... case reserved_LAST: break;` and add it to all switches in question. Addition itself could also be automated via simple Perl script. I'm afraid that's your only chance as there's _no_ flag/pragma to control application of `-Wswitch`. – yugr May 05 '19 at 08:49

0 Answers0