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

--- Comment #6 from Harald Anlauf <anlauf at gmx dot de> ---
(In reply to Lorenz Hüdepohl from comment #4)
> > The right way to fix the problem is to fix the program
> > by using an appropriate programming style.  Writing
> >
> >      real    :: a(n1:)   ! not:  real :: a(n1:n2)
> >
> > one gets the expected check
> 
> I realize that, and when I write my own code I would never
> use such a construction. However, sometimes one is burdened
> with existing code in which small treasures such as this kind
> of bug are hidden.
> 
> I was hoping that with -fcheck=bounds I could find this.

As Dominique pointed out, this is not the way bounds checking
is usually implemented.  Checks are local.

Fortran allows you to intentionally bypass all checks by
using explicit size specifications.  You can even use different
ranks of the array in the caller and the callee.  If you lie to
the compiler in that situation about proper sizes, then you lose.

> If the code was correct already there would be no need for
> any kind of runtime checks, right?

Right.  But IMHO bounds check are not applicable here.
Try other compilers.  I'd expect them to behave similarly.

Use valgrind or -fsanitize=address to detect this kind of
memory problems.  (I solved my linking problem by updating
to current trunk).

Reply via email to