From 5229d4b3123a13c88b1e070bd7b5cfbabba4cf6d Mon Sep 17 00:00:00 2001 From: David Rowley Date: Thu, 1 Oct 2026 15:16:42 +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/func-math.sgml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/doc/src/sgml/func/func-math.sgml b/doc/src/sgml/func/func-math.sgml index 9dcf97e7c9e..4b5d587b368 100644 --- a/doc/src/sgml/func/func-math.sgml +++ b/doc/src/sgml/func/func-math.sgml @@ -26,6 +26,13 @@ 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