From 93bfc76216f685739c87656c7fc2067f69ee5593 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20=C5=9Aliwak?= Date: Thu, 25 Mar 2021 17:54:43 +0100 Subject: [PATCH] docs: Mention explicitly that bitwise operators do not perform overflow/underflow checks --- docs/control-structures.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/control-structures.rst b/docs/control-structures.rst index ed19dd663..2549aafbc 100644 --- a/docs/control-structures.rst +++ b/docs/control-structures.rst @@ -531,6 +531,12 @@ and will wrap without an error if used inside an unchecked block: It is not possible to disable the check for division by zero or modulo by zero using the ``unchecked`` block. +.. note:: + Bitwise operators do not perform overflow or underflow checks. + This is particularly visible when using bitwise shifts (``<<``, ``>>``, ``<<=``, ``>>=``) in + place of integer division and multiplication by a power of 2. + For example ``type(uint256).max << 3`` does not revert even though ``type(uint256).max * 8`` would. + .. note:: The second statement in ``int x = type(int).min; -x;`` will result in an overflow because the negative range can hold one more value than the positive range.