*This is an unofficial snapshot of the ISO/IEC JTC1 SC22 WG21
Core Issues List revision 115a.
See http://www.open-std.org/jtc1/sc22/wg21/ for the official
list.*

2024-07-24

#### 854.
Left shift and unsigned extended types

**Section: **7.6.7 [expr.shift]
**Status: **CD2
**Submitter: **Daniel Krügler
**Date: **5 April, 2009

[Voted into WP at October, 2009 meeting.]

According to 7.6.7 [expr.shift] paragraph 2,

The value of `E1 << E2` is `E1` (interpreted as a
bit pattern) left-shifted `E2` bit positions; vacated bits are
zero-filled. If `E1` has an unsigned type, the value of the
result is `E1` multiplied by the quantity 2 raised to the power
`E2`, reduced modulo `ULLONG_MAX+1` if `E1` has
type `unsigned long long int`, `ULONG_MAX+1` if
`E1` has type `unsigned long int`, `UINT_MAX+1`
otherwise.

This specification does not allow for extended types with rank
greater than `long long`; in particular, it says that the
value of a shifted unsigned extended type is truncated as if it were
the same width as an `unsigned int`.

It's unclear that the second sentence has any normative value; it
might be better to relegate it to a note or omit it than to correct
it.

**Proposed resolution (July, 2009):**

Change 7.6.7 [expr.shift] paragraphs 2-3 as follows:

The value of `E1 << E2` is `E1`
~~(interpreted as a bit pattern)~~ left-shifted `E2` bit
positions; vacated bits are zero-filled. If `E1` has an
unsigned type, the value of the result is `E1` ~~multiplied
by the quantity 2 raised to the power ~~`E2` ×
2^{E2}, reduced modulo
`ULLONG_MAX+1` if `E1` has type `unsigned long
long int`, `ULONG_MAX+1` if `E1` has type
`unsigned long int`, `UINT_MAX+1` otherwise.
[*Note:* the constants `ULLONG_MAX`, `ULONG_MAX`,
and `UINT_MAX` are defined in the header
`<climits>`. —*end note*] one more
than the maximum value representable in the result type. Otherwise,
if `E1` has a signed type and nonnegative value, and
`E1` × 2^{E2} is representable in the
result type, then that is the resulting value; otherwise, the behavior
is undefined.

The value of `E1 >> E2` is `E1` right-shifted
`E2` bit positions. If `E1` has an unsigned type or if
`E1` has a signed type and a nonnegative value, the value of
the result is the integral part of the quotient of `E1`
~~divided by the quantity 2 raised to the power ~~`E2`
/ 2^{E2}. If `E1` has a signed
type and a negative value, the resulting value is
implementation-defined.