<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/78939>78939</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[Flang] No error checking if the type specifier specified in the allocate statement is different from the declaration
</td>
</tr>
<tr>
<th>Labels</th>
<td>
flang:frontend
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
ohno-fj
</td>
</tr>
</table>
<pre>
```
Version of flang-new : 18.0.0(0fe86f9c518fb1296bba8d66ce495f9dfff2c435)
```
When allocating a `character` type pointer variable, an error is not checked if the type specifier specified
in `allocate` statement is different from the declaration.
Gfortran and ifort detect compilation errors.
Specifying `parameter` attribute in the type declaration of the variable (nn) checks for errors. This program (snggz792_12.f90) and results are attached at the end.
The following are the test program, Flang-new, Gfortran and ifort compilation result.
snggz792_11.f90:
```fortran
module m1
integer::nn=1
! integer,parameter::nn=1
end module m1
program main
use m1
character(nn),pointer::c1s
kk=0
allocate(character(2)::c1s,stat=kk)
print *,kk
end program main
```
```
$ flang-new snggz792_11.f90
$
```
```
$ gfortran snggz792_11.f90
snggz792_11.f90:8:28:
8 | character(nn),pointer::c1s
| 1
Error: ‘c1s’ at (1) must have constant character length in this context
snggz792_11.f90:10:25:
10 | allocate(character(2)::c1s,stat=kk)
| 1
Error: Allocating c1s at (1) with type-spec requires the same character-length parameter as in the declaration
$
```
```
$ ifort snggz792_11.f90
snggz792_11.f90(8): error #6591: An automatic object is invalid in a main program. [C1S]
character(nn),pointer::c1s
-------------------------^
compilation aborted for snggz792_11.f90 (code 1)
$
```
snggz792_12.f90:
```fortran
module m1
! integer::nn=1
integer,parameter::nn=1
end module m1
program main
use m1
character(nn),pointer::c1s
kk=0
allocate(character(2)::c1s,stat=kk)
print *,kk
end program main
```
```
$ flang-new snggz792_12.f90
error: Semantic errors in snggz792_12.f90
./snggz792_12.f90:10:26: error: Character length of allocatable object in ALLOCATE must be the same as the type-spec
allocate(character(2)::c1s,stat=kk)
^^^
$
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsVk2TozYT_jXypcsuSRgbDj547fF72Xpz2K3kmBLQAq1BciQxm82vTwmB8dozu5nMNZQL8yH10x9PP7RwTtUacUfSDyQ9LkTvG2N3ptFmKb8sClN925ENHX_0SOj-V7ROGQ1GgmyFrpcavwJJ9sCyFV1RwjMqMdvIvExZJgvG801RiKzabEpc56nMKyklL9dJSngeTd4hxPNvDWoQbWtK4ZWuQQDZ0LIRVpQeLdlQ8N8uCBejtEcLz8IqUbRI-AGEBrTWWFAOtPFQNliesQIlwTcY97kLlkoqtNerKuIqHYBGYAw4zguPHWof7FVKSrThRlrTDfYqLFthhVdGrwCilf9JY70VGoQOuMZ6qNBj6aE03UW1w-ropVvdhv1p8OZbiJhs6EVY0eEYr_DeqqL3CErPgdygh5qE51MugPBMa8LzmAEH0tgJEz43ysHFmtqKLix0uq7_2ub8d8ZXMqdhV_Ddoutb70BYDA6IssEKhB9wUFff-f65QZCmbc3XoWAWo5fo_AQUqnOaWBNuXsjTbYIi-ncgs59s8DPZ35FotBifdqbqW4SOxVuAwJYabdiW7LUmyXF8RTib3_LDnPmHlagruLMbz1M2O6H0hNe7W_SZv2NlAlJkcMQpmZvWns8kOdLp7kpInt0a4cHGdSc_BK6S5Hg-X5sL4GKV9kD4nvDD-TzH8Ojui414_5Cvbxr_vhrTkrfZqycWvGjuseIZSfY8m0s_BgqQAdke4G15Dkfc9eox1u8ptE6QOvLESUZJngUz43UeuoLwjIXO6XrnoRHPCKXRzgvtZ5egRV37JjaxcmGFxz_9a7GycOLpY7CMjm6_gxo_i_0-8P2sxyVztxF_Vb4ZBGkZ9BQs_tEri25QACc6nONfjvFfOwyEmxTtRsz-JZWihvwjHvEsiykavxaEJ5s0Z0OcGkTvTSe8KsEUX4Jwq-Dls2hVFbwVQ9tMPbQKeUw_HNgnkh7f3uzL1w6SPsUVt6IoCmM9VoOa38UUylGaCoHNH9c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