From d6896c056d69da2a451e032cd7b9823de299cdfb Mon Sep 17 00:00:00 2001 From: David Rowley Date: Thu, 1 Oct 2026 15:18:11 +1300 Subject: [PATCH] Doc: mention platform-dependent behavior of bitshift operators There have been several recent complaints that << and >> don't behave the same way on all supported platforms. There is a risk that << overflows the signed integer type, which is undefined behavior, and there are platform-dependent behaviors from shifting by numbers of bits >= the bitwidth of the type, and also from shifting by negative values. Document this to warn unsuspecting users of these facts. Author: David Rowley Reviewed-by: Tom Lane Discussion: https://postgr.es/m/CAApHDvr0O6ZF8NO=Rq9Q+Sz=FHT=NZ1kkNTXZDcNph-OWuk7TQ@mail.gmail.com Backpatch-through: 14 --- doc/src/sgml/func.sgml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/doc/src/sgml/func.sgml b/doc/src/sgml/func.sgml index 8456d816142..37c471219d0 100644 --- a/doc/src/sgml/func.sgml +++ b/doc/src/sgml/func.sgml @@ -851,6 +851,13 @@ repeat('Pg', 4) PgPgPgPg are resolved by using the type appearing later in these lists. + + The behavior of bitwise shifting, both left and right, has + platform-dependent behavior both in cases of left shifting that results in + a signed overflow and in cases of the results of shifting by more bits + than exist in the type or from shifting by a negative value. + + Mathematical Operators