<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/140941>140941</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Flang semantic error depending on definition order of size/dimension arguments
</td>
</tr>
<tr>
<th>Labels</th>
<td>
flang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
hansec
</td>
</tr>
</table>
<pre>
Hello,
Flang (20.1.5) currently fails in some cases where a size argument, that is also an argument itself is defined after it’s first use. For example, the following simple test case
```fortran
MODULE test_mod
IMPLICIT NONE
CONTAINS
SUBROUTINE test_sub(a,n)
INTEGER(4), INTENT(in) :: a(n)
INTEGER(8), INTENT(in) :: n
END SUBROUTINE test_sub
END MODULE test_mod
```
results in the error
```
./test.F90:6:27: error: The type of 'n' has already been implicitly declared
INTEGER(8), INTENT(in) :: n
^
./test.F90:4:23: Implicit declaration of 'n'
SUBROUTINE test_sub(a,n)
^
```
Note that while the error points to the subroutine definition the actual error appears to be caused by implicit definition of `n` in the declaration of `a`. Indeed, if `n` is defined before `a` or if `n` is of default integer type (4 bytes in this case) the error is not thrown.
To be explicit both of the following work
```fortran
INTEGER(4), INTENT(in) :: a(n)
INTEGER, INTENT(in) :: n
```
```fortran
INTEGER(8), INTENT(in) :: n
INTEGER(4), INTENT(in) :: a(n)
```
I am not sure if this is Flang being pedantic or not, but every other Fortran compiler I work with (Intel, GCC, Cray) supports this ordering of code so it would be nice to not have to change things just to support Flang. This seems somewhat related to [#106021](https://github.com/llvm/llvm-project/issues/106021).
I tried to look around to see if this was reported earlier but couldn’t find anything. So apologies if this is a repeat. Thanks!
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJykVt-P2jgQ_mvMy-gixyGQPOQhZaGH1LKnln0-OcmEuGvsyHaWcn_9aRLY3bJ3W90VIQXs-fHNN984lt6rg0EsWPqBpXczOYTOuqKTxmM9q2xzLn5HrS0TK8ZLxsuNluYATG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