Youjun Hu
Youjun Hu

Reputation: 1324

Fortran (re-)allocation on assignment and gfortran warnings

A simple code:

program main
integer, allocatable :: A(:,:)
integer              :: B(3,4)
B=1
A = B  !A will get allocated, with the same shape and bounds as B
end program main

Compiling the above code with: gfortran-8 -std=f2008 -fcheck=all -Wall -Wextra -fbounds-check -fimplicit-none array.f90

I got the following warning:

Warning: ‘a.offset’ may be used uninitialized in this function Warning: ‘a.dim[0].lbound’ may be used uninitialized in this function Warning: ‘a.dim[0].ubound’ may be used uninitialized in this function [-Wmaybe-uninitialized]

Is there somebody having an idea of why I got these warnings?

Upvotes: 5

Views: 945

Answers (1)

This is a well known GCC bug https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77504 that has been reported in many duplicates to the bugzilla (even by myself) - see the Duplicates section for the other incarnations.

As far as I understand it the actual code generated by the compiler should work correctly and it is just an incorrect warning. As Steve pointed out in the comment, use -Wno-maybe-uninitialized to hide this warning. I have included it into my build scripts as well.

Upvotes: 2

Related Questions