https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120788

anlauf at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |WAITING
   Last reconfirmed|                            |2025-06-23
     Ever confirmed|0                           |1

--- Comment #1 from anlauf at gcc dot gnu.org ---
You are invoking undefined behavior.

If you want wrapping on overflow, you can use -fwrapv, which gives:

 hgng =  -2147483648
 hgt + 1 =  -2147483648
 hgt + 1 /= hgng =  F
 hgt + 1 == hgng =  T

You can see where your code fails by compiling with -fsanitize=undefined:

 hgng =  -2147483648
pr120788.f90:8:33: runtime error: signed integer overflow: 2147483647 + 1
cannot be represented in type 'integer(kind=4)'
 hgt + 1 =  -2147483648
 hgt + 1 /= hgng =  F
 hgt + 1 == hgng =  T

Reply via email to