Skip to contentSkip to conversation

linux-user: avoid -Werror=int-in-bool-context

PATCH In review Paolo Bonzini 4 participants 5 messages Sep 19, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 linux-user: avoid -Werror=int-in-bool-context

linux-user is failing to compile on Fedora 43:

../linux-user/strace.c:57:66: error: enum constant in boolean context [-Werror=int-in-bool-context]
57 | #define FLAG_BASIC(V, M, N) { V, M | QEMU_BUILD_BUG_ON_ZERO(!(M)), N }

The warning does not seem to useful and we could even disable it, but the workaround is simple in this case.

---
 linux-user/strace.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
linux-user/strace.c +1 -1
index 1233ebceb08..758c5d32b6c 100644
@@ -54,7 +54,7 @@ struct flags {
 };
 
 /* No 'struct flags' element should have a zero mask. */
-#define FLAG_BASIC(V, M, N)      { V, M | QEMU_BUILD_BUG_ON_ZERO(!(M)), N }
+#define FLAG_BASIC(V, M, N)      { V, M | QEMU_BUILD_BUG_ON_ZERO((M) == 0), N }
 
 /* common flags for all architectures */
 #define FLAG_GENERIC_MASK(V, M)  FLAG_BASIC(V, M, #V)
Signature · 1 line
2.51.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · Paolo Bonzini

linux-user is failing to compile on Fedora 43:

../linux-user/strace.c:57:66: error: enum constant in boolean context [-Werror=int-in-bool-context]
57 | #define FLAG_BASIC(V, M, N) { V, M | QEMU_BUILD_BUG_ON_ZERO(!(M)), N }

The warning does not seem to useful and we could even disable it, but the workaround is simple in this case.

Quoted 6 lines
---
 linux-user/strace.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

With regards,
Daniel

Signature · 3 lines
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
#2 lore raw
In reply to Paolo Bonzini
Quoted 8 lines · Paolo Bonzini

linux-user is failing to compile on Fedora 43:

../linux-user/strace.c:57:66: error: enum constant in boolean context [-Werror=int-in-bool-context]
57 | #define FLAG_BASIC(V, M, N) { V, M | QEMU_BUILD_BUG_ON_ZERO(!(M)), N }

The warning does not seem to useful and we could even disable it, but the workaround is simple in this case.

I'm surprised this is the only place in the codebase where we treat an int as a bool...

-- PMM

#3 lore raw
Quoted 4 lines · Peter Maydell
Quoted 3 lines · Paolo Bonzini

linux-user is failing to compile on Fedora 43:

Quoted 8 lines
Quoted 5 lines

../linux-user/strace.c:57:66: error: enum constant in boolean context [-Werror=int-in-bool-context]
57 | #define FLAG_BASIC(V, M, N) { V, M | QEMU_BUILD_BUG_ON_ZERO(!(M)), N }

The warning does not seem to useful and we could even disable it, but the workaround is simple in this case.

I'm surprised this is the only place in the codebase where we treat an int as a bool...

It definitely isn't. Idiomatic C...

#4 lore raw
In reply to Peter Maydell
Quoted 4 lines · Peter Maydell
Quoted 3 lines · Paolo Bonzini

linux-user is failing to compile on Fedora 43:

Quoted 8 lines
Quoted 5 lines

../linux-user/strace.c:57:66: error: enum constant in boolean context [-Werror=int-in-bool-context]

    57 | #define FLAG_BASIC(V, M, N)      { V, M | QEMU_BUILD_BUG_ON_ZERO(!(M)), N }

The warning does not seem to useful and we could even disable it, but the workaround is simple in this case.

I'm surprised this is the only place in the codebase where we treat an int as a bool...

There are some heuristics about suspicious uses. Examples in the documentation include "if (a <= b ? 2 : 3)" and "1 << a" in boolean context.

Paolo