[flang-commits] [flang] [flang][semantics] Allow forward-typed PARAMETER constants under IMPLICIT NONE (PR #203398)
via flang-commits
flang-commits at lists.llvm.org
Thu Jun 11 19:10:47 PDT 2026
================
@@ -0,0 +1,41 @@
+! RUN: not %flang_fc1 -pedantic %s 2>&1 | FileCheck %s
+! Test extension: a named constant defined by a PARAMETER statement may appear
+! before its explicit type declaration in a scope with IMPLICIT NONE(TYPE).
+! It acquires the type it would have had under implicit typing rules, which a
+! later explicit declaration must match.
+
+! Forward reference accepted, matching INTEGER declaration appears later.
+!CHECK: warning: 'n' was used without (or before) being explicitly typed
+subroutine s1
+ implicit none
+ parameter(n=4096)
+ integer n
+end
+
+! The would-be-implicit type need not be INTEGER; a matching REAL declaration
+! is accepted.
+!CHECK: warning: 'x' was used without (or before) being explicitly typed
+subroutine s2
+ implicit none
+ parameter(x=1.5)
+ real x
+end
+
+! A later declaration whose type differs from the would-be-implicit type is
+! rejected.
+!CHECK: warning: 'm' was used without (or before) being explicitly typed
+subroutine s3
+ implicit none
+ parameter(m=4096)
+!CHECK: error: The type of 'm' has already been implicitly declared as INTEGER(4)
----------------
mleair wrote:
When you say 'm' has been implicitly declared as INTEGER(4), is that based off of the value assigned to 'm' or is that based on Fortran's implicit type rules which state that variables that begin with 'i' through 'n' are integer?
Also, is 'm' technically declared implicitly with default integer and not necessarily integer(4)?
Is this extension affected when this and the other tests do not have an "implicit none" statement?
https://github.com/llvm/llvm-project/pull/203398
More information about the flang-commits
mailing list