]> git.hungrycats.org Git - bees/commit
fd: delete Fd::operator bool so "if (fd)" fails to compile
authorZygo Blaxell <bees@furryterror.org>
Sat, 10 Oct 2026 18:50:13 +0000 (14:50 -0400)
committerZygo Blaxell <bees@furryterror.org>
Sat, 10 Oct 2026 18:55:23 +0000 (14:55 -0400)
commitfacfc3fc91f066ce38327ab526e8d60f35b7b65f
tree62c308cae1731fb5c8624b841f7c23067a539bd4
parentddbded3f026973132d2d1c25c70c6adf17adfa17
fd: delete Fd::operator bool so "if (fd)" fails to compile

Fd has operator int() and operator!(), but no operator bool.  In a
boolean context such as "if (fd)", "fd && x" or "fd ? a : b", the
compiler converts through operator int, and an empty Fd is -1, which
is true.  "!fd" works, which makes the positive form look safe when it
is not.  Several such tests have crept in.

Declare an explicit, deleted operator bool.  An explicit conversion is
only considered in boolean contexts, where it is an exact match and
wins over operator int, so those uses now fail to compile.  Conversions
to int are unaffected.  Test an Fd with "!!fd" or "!fd".

Assisted-by: Claude-Code:claude-opus-5-5
include/crucible/fd.h