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

            Bug ID: 86313
           Summary: make -Warray-temporaries less noisy
           Product: gcc
           Version: 8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: janus at gcc dot gnu.org
  Target Milestone: ---

It seems that the flag -Warray-temporaries can produce excessive amounts of
warnings, even on cases that are not really problematic, like this one:


program Warray_temps
integer, dimension(1:2) :: arr
integer :: alpha, beta
alpha = 1
beta = 2
arr(1:2) = (/ alpha, beta /)
print *, arr
end


Here I get:

 arr(1:2) = (/ alpha, beta /)
           1
Warning: Creating array temporary at (1) [-Warray-temporaries]


This occurs only if alpha and beta are not declared as PARAMETERS and get their
value at runtime. Of course this minimal reproducer is very much simplified.
The logic that determines alpha and beta can be more complicated in real life.


I don't think the warning is very helpful. Some discussion:

1) The compiler does not actually have to create an array temp here, I think.
One could as well implement this statement without temp (just two scalar
assignments). In that sense the temporary is an implementation detail that is
not imposed by the programmer, but by the compiler. It may be a good idea to
get rid of it for such cases.

2) The temporary is not very large. It's a fixed-size array with just two
elements. Copying this to the destination array is not extremely expensive
(compared to a huge array temporary with thousands of elements). One might
introduce some cut-off value and inhibit the warning for 'small' fixed-size
arrays (with a suitable definition of 'small').

Reply via email to