On 10/7/19 9:30 PM, Junio C Hamano wrote: > SZEDER Gábor <szeder.dev@xxxxxxxxx> writes: > >>> func(PROGRESS | REGRESS); >>> func(PROGRESS + REGRESS); >>> func(PROGRESS * 3); >>> } >>> >>> how caller came about to give 3? >> >> No, they tend to show (PROGRESS | REGRESS), at least both gdb and lldb >> do. > > OK. > >> If the enum has only constants with power-of-two values, then that >> is the right way to write it, and the other two are asking for trouble > > If the programmer and the debugger knows the constants are used to > represent bits that can be or'ed together, what you say is correct, > but that is entirely irrelevant. > > What I was worried about is that the constants that are used to > represent something that are *NOT* set of bits (hence "PROGRESS * 3" > may be perfectly a reasonable thing for such an application) may be > mistaken by an overly clever debugger and "3" may end up getting > shown as "PROGRESS | REGRESS". When there are only two constants > (PROGRESS=1 and REGRESS=2), we humans nor debuggers can tell if that > is to represent two bits that can be or'ed together, or it is an > enumeration. > > Until we gain the third constant, that is, at which time the third > one may likely be 3 (if enumeration) or 4 (if bits). > I tried to see how lldb would handle the "PROGRESS * 3" scenario but I was unable to get lldb to display the "PROGRESS | REGRESS" format even when ORing the flags: (lldb) l 399 399 enum test_flags { 400 TEST_FLAG_1 = 1 << 0, 401 TEST_FLAG_2 = 1 << 1, 402 }; 403 404 enum test_flags flags_1 = TEST_FLAG_1; 405 enum test_flags flags_2 = TEST_FLAG_2; 406 enum test_flags flags_both = TEST_FLAG_1 | TEST_FLAG_2; 407 408 if (flags_1 || flags_2 || flags_both) (lldb) p flags_1 (test_flags) $0 = TEST_FLAG_1 (lldb) p flags_2 (test_flags) $1 = TEST_FLAG_2 (lldb) p flags_both (test_flags) $2 = 3 (lldb) fr v flags_both (test_flags) flags_both = 3 (lldb) fr v --format enum flags_both (test_flags) flags_both = 3 (lldb) version lldb-902.0.79.7 Swift-4.1 Is there something that needs to be adjusted in the config or with --format to display "TEST_FLAG_1 | TEST_FLAG_2" in this example? Thanks, William