The following program compiled with gfortran, ifort and ifx is computing correctly 2**31-1 when n is declared as int32 (although I would not have been surprised if it had failed):
program main
use iso_fortran_env
integer(int32) :: n
integer :: i
i = 31
n = 2**i - 1
print *, n, kind(n)
end program main
program main
use iso_fortran_env
integer(int32) :: n
integer :: i
i = 31
n = 2**i
print *, n, kind(n) ! ==> -2147483648 4
n = n - 1
print *, n, kind(n) ! ==> 2147483647 4
end program main
It seems double overflow occurring here and the result is expected.
In 64-bit version it is really odd, looks like ifort treats the first result (2**31) as 64-bit value of -2147483648, subtracting 1 gives -2147483649