public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/96266] New: Macro defined as enum in parens resolves to 1
@ 2020-07-21 11:55 ethouris at gmail dot com
  2020-07-21 12:05 ` [Bug c++/96266] " jakub at gcc dot gnu.org
  2020-07-21 12:34 ` redi at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: ethouris at gmail dot com @ 2020-07-21 11:55 UTC (permalink / raw)
  To: gcc-bugs

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.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-07-21 12:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-21 11:55 [Bug c++/96266] New: Macro defined as enum in parens resolves to 1 ethouris at gmail dot com
2020-07-21 12:05 ` [Bug c++/96266] " jakub at gcc dot gnu.org
2020-07-21 12:34 ` redi at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).