Skip to content

Commit ab22a71

Browse files
committed
refactor: cast bool to int to silence compiler warning
This fixes -Wbitwise-instead-of-logical compiler warnings: node/interfaces.cpp:544:16: warning: use of bitwise '&' with boolean operands [-Wbitwise-instead-of-logical] return FillBlock(ancestor, ancestor_out, lock, active) & FillBlock(block1, block1_out, lock, active) & FillBlock(block2, block2_out, lock, active); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ && node/interfaces.cpp:544:16: note: cast one or both operands to int to silence this warning node/interfaces.cpp:544:16: warning: use of bitwise '&' with boolean operands [-Wbitwise-instead-of-logical] return FillBlock(ancestor, ancestor_out, lock, active) & FillBlock(block1, block1_out, lock, active) & FillBlock(block2, block2_out, lock, active); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ && node/interfaces.cpp:544:16: note: cast one or both operands to int to silence this warning 2 warnings generated. A similar change was recently made to libsecp in commit 16d13221 for the same reason.
1 parent 3a36ec8 commit ab22a71

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/node/interfaces.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -540,8 +540,11 @@ class ChainImpl : public Chain
540540
const CBlockIndex* block2 = m_node.chainman->m_blockman.LookupBlockIndex(block_hash2);
541541
const CBlockIndex* ancestor = block1 && block2 ? LastCommonAncestor(block1, block2) : nullptr;
542542
// Using & instead of && below to avoid short circuiting and leaving
543-
// output uninitialized.
544-
return FillBlock(ancestor, ancestor_out, lock, active) & FillBlock(block1, block1_out, lock, active) & FillBlock(block2, block2_out, lock, active);
543+
// output uninitialized. Cast bool to int to avoid -Wbitwise-instead-of-logical
544+
// compiler warnings.
545+
return int{FillBlock(ancestor, ancestor_out, lock, active)} &
546+
int{FillBlock(block1, block1_out, lock, active)} &
547+
int{FillBlock(block2, block2_out, lock, active)};
545548
}
546549
void findCoins(std::map<COutPoint, Coin>& coins) override { return FindCoins(m_node, coins); }
547550
double guessVerificationProgress(const uint256& block_hash) override

0 commit comments

Comments
 (0)