Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow implicit none to appear before use statements #239

Open
Beliavsky opened this issue Nov 3, 2021 · 5 comments
Open

Allow implicit none to appear before use statements #239

Beliavsky opened this issue Nov 3, 2021 · 5 comments
Labels
Clause 8 Standard Clause 8: Attribute declarations and specifications

Comments

@Beliavsky
Copy link

Beliavsky commented Nov 3, 2021

Currently implicit none must appear after use statements in a module or main program. Could this restriction be removed? As long as Fortran has implicit typing, implicit none should appear at the beginning of a main program or module. It would convenient if you could just put it on the second line of source files and look for it there, instead of looking for it under any number of use statements.

I would not call this a big improvement, but unless it is difficult for compiler writers to implement, it may be worth doing.

@certik
Copy link
Member

certik commented Nov 3, 2021

Indeed. I also feel it would be much more natural right after the program or module. (I edited your post, you said it currently appears before use, so I changed it to after use.)

@FortranFan
Copy link
Member

FortranFan commented Nov 3, 2021

@Beliavsky wrote Nov. 3, 2021 10:22 AM EDT:

Currently implicit none must appear after use statements in a module or main program. Could this restriction be removed?

My hunch is there will be a lot of resistance to this among the committee.

Note the semantics of implicit none are but part of those with the implicit statement.

The current ordering appears to be intended to allow instructions such as the following and to keep matters simpler for the compiler implementations:

   use foo_m, only : foo_t
   ..
   implicit type(foo_t) (f)  !<-- implicit mapping of type(foo_t) to letter 'f' so that any undeclared object
                             !    beginning with letter 'f' is *implicitly* of type(foo_t)

A less troublesome but a wholesome and truly valuable step forward for Fortran will be #218. Then coders don't have to bother at all about their "desired" place for implicit none; that will be the default.

@certik
Copy link
Member

certik commented Nov 3, 2021

@FortranFan good points. One option is to allow the implicit both after and before use. That way if you use implicit type(foo_t) (f) then you have to put it after use, but implicit none can come before.

@klausler
Copy link

klausler commented Nov 3, 2021

The problem here isn't that implicit none isn't allowed before a use, it's that use (and import) are required to appear first. That's what could be relaxed -- both of them could really appear anywhere in a specification-part, including this particular desired use case (after implicit none).

So long as the names that 'use' and import pull into the scope are distinct, there's no semantic ambiguity introduced by allowing them to appear later; and when the names clash(*) with others in the scope, that's a situation that a compiler already has to cope with today since it can arise using just use and import. Ditto with forward references to derived types, that's already possible in Fortran.

((*) not all cases of having a name already in scope and being equivalent to a name from a use/import are errors)

@ashe2
Copy link

ashe2 commented Nov 4, 2021

Another option would be to allow use, import, and implicit none statements to occur together in any order at the beginning of a specification part. Other implicit statements would not be allowed in this part so it wouldn't add new forward referencing.

implicit none is already treating differently from other implicit statements in that the latter can occur after parameter statements. Also, other implicit statements shouldn't be used in new code, at least in my opinion.

@certik certik added the Clause 8 Standard Clause 8: Attribute declarations and specifications label Apr 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Clause 8 Standard Clause 8: Attribute declarations and specifications
Projects
None yet
Development

No branches or pull requests

5 participants