You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Allocation on assignment of an allocatable array is part of the language, but sometimes people do it inadvertently (I have), so an optional warning could be useful. Ideally the warning would not occur when the allocatable array is set to an array of the same size or to a scalar. For example,
integer, allocatable :: v(:), w(:)
v = [3, 5] ! warn
w = [2, 4, 6] ! warn
v =0 ! don't warnv = v + 10 ! don't warn
v = w ! warn
I think @Beliavsky's idea is to only warn if the compiler / static analyzer can't figure out and guarantee at compile time that no reallocation will happen. This can't be done in general, so there will be some warnings, and a user can silence them by converting to v(:) = [3, 5].
I think that would be useful. The way LFortran does it is that we currently don't allow LHS reallocation by default (you have to enable it with a compiler option). So it forces you to write your code in such a way that the LHS always has the correct pre-allocated size. Then if you compile with LHS reallocation (in any compiler), you know it will not reallocate silently, you will only incur the (hopefully small) runtime check.
Allocation on assignment of an allocatable array is part of the language, but sometimes people do it inadvertently (I have), so an optional warning could be useful. Ideally the warning would not occur when the allocatable array is set to an array of the same size or to a scalar. For example,
@certik has a relevant post https://fortran-lang.discourse.group/t/allocatable-vs-adjustable/8957/59
The text was updated successfully, but these errors were encountered: