[Flang] Incorrect diagnose for DATA statement
Consider the following code:
PROGRAM Misc7
INTEGER A(3), B, C(3)
DATA A(1:2) /2*1/ A(2:3) /2*2/
DATA C /3*1/ C /3*2/
DATA B /1/ B /2/
PRINT*, A
PRINT*, C
PRINT*, B
IF (ANY(A(1:1) .NE. 1 )) ERROR STOP 11
IF (ANY(A(2:3) .NE. 2 )) ERROR STOP 12
IF (ANY(C(1:3) .NE. 2 )) ERROR STOP 13
IF (B .NE. 2 ) ERROR STOP 14
END
Flang currently issues error messages
54:11: error: DATA statement initializations affect 'a(2_8)' more than once
INTEGER A(3), B, C(3)
^
54:17: error: DATA statement initializations affect 'b' more than once
INTEGER A(3), B, C(3)
^
54:20: error: DATA statement initializations affect 'c(1_8)' more than once
INTEGER A(3), B, C(3)
^
It doesn't seem correct to me.
@llvm/issue-subscribers-bug
Author: Daniel Chen (DanielCChen)
END
Flang currently issues error messages
54:11: error: DATA statement initializations affect 'a(2_8)' more than once INTEGER A(3), B, C(3) ^ 54:17: error: DATA statement initializations affect 'b' more than once INTEGER A(3), B, C(3) ^ 54:20: error: DATA statement initializations affect 'c(1_8)' more than once INTEGER A(3), B, C(3) ^
It doesn't seem correct to me.
</details>
@llvm/issue-subscribers-flang-frontend
Author: Daniel Chen (DanielCChen)
END
Flang currently issues error messages
54:11: error: DATA statement initializations affect 'a(2_8)' more than once INTEGER A(3), B, C(3) ^ 54:17: error: DATA statement initializations affect 'b' more than once INTEGER A(3), B, C(3) ^ 54:20: error: DATA statement initializations affect 'c(1_8)' more than once INTEGER A(3), B, C(3) ^
It doesn't seem correct to me.
</details>
Normally, "It doesn't seem correct to me" is followed by a comma and a clause starting with "because ...". flang's behavior is correct.
Fortran 2023, 8.4 Initialization ... A variable, or part of a variable, shall not be explicitly initialized more than once in a program. ...
You are right. The standard indeed doesn't allow multiple initialization on the same variable. I missed it. Thanks for pointing it out.