https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96266
Bug ID: 96266 Summary: Macro defined as enum in parens resolves to 1 Product: gcc Version: 7.5.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: ethouris at gmail dot com Target Milestone: --- Created attachment 48906 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48906&action=edit Preprocessed C++ file with example. I'm attaching a quite long preprocessed file, but all "simplified examples" didn't reproduce it. I'm not even sure if this is a bug or a feature (maybe something related to resolving into `defined()` pp function), but it definitely works not according to the intention. This can also be my mistake, but if so, I'm completely unable to find it despite best efforts. In short: 1. There's an enum defined, one value is, say, `UPDATE = 0x10` 2. There's a macro defined: `#define ETONLY (UPDATE)` 3. The variable is passed as `int x = 0x11`. 4. The expression `x & ETONLY` resolves to... 1 (not 0x10). Workaround: 1. Define `ETONLY` as `(0 | UPDATE)` 2. Expression `x & int(ETONLY)` resolves correctly to 0x10. Tested on gcc 7.5 and some older, including 4.4.