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

surprising interactions: interface function can make enum value invisible #439

Closed
pawosm-arm opened this issue Apr 5, 2018 · 6 comments
Closed
Labels

Comments

@pawosm-arm
Copy link
Collaborator

Following code:

program enum
  implicit none
  enum, bind(C)
    enumerator ::  SUCCESS = 0
    enumerator ::  FAILURE
  end enum

  interface
    function something()
      integer(kind(FAILURE)) :: something
    end function
  end interface

  print *, SUCCESS
  print *, FAILURE
end program enum

Can't be compiled due to an error:

F90-S-0038-Symbol, failure, has not been explicitly declared (enum.f08)
  0 inform,   0 warnings,   1 severes, 0 fatal for enum

Changing type of function in the interface (not to use enum value there) causes this program to build.
This is similar example of surprising interactions as in #367.

@nncarlson
Copy link

nncarlson commented Apr 5, 2018

The interface block for something is a separate scoping unit; it inherits nothing from the surrounding scope. That includes FAILURE as well as the implicit none. Did you compile this with the "-u" flag (or whatever the flang equivalent of "no implicit typing" is)? The error you got would be consistent with "-u". However without that, the example should have compiled fine with one caveat -- but it is certainly not what you intended. FAILURE is a default real in the interface block under implicit typing rules in that scope. So its real kind is being used as an integer kind value. It's likely to be a valid integer kind, but not what was intended.

This is what you need:

interface
  function something()
    import FAILURE
    implicit none
    integer(kind(FAILURE)) :: something
  end function
end interface

If flang was giving the error without "-u" then that is a flang bug; it's apparently letting the implicit none leak into the interface block when it shouldn't

@pawosm-arm
Copy link
Collaborator Author

Hi,
I'm not building with -u flag and I forgot to mention that my first observation was that the problem goes away when I removed print *, FAILURE line which made me believe that this enum constant somehow became invisible.
Also note that gfortran builds that code without any changes.

@nncarlson
Copy link

Also note that gfortran builds that code without any changes.

which it should, however, the FAILURE in the interface block is a local real variable, and not the enum FAILURE as was surely intended.

@pawosm-arm
Copy link
Collaborator Author

pawosm-arm commented Apr 6, 2018

How do you use -u flag with flang? It doesn't seem to be documented. Unfortunately, both -fimplicit-none and -fno-implicit-none are ignored by flang:

warning: argument unused during compilation: '-fno-implicit-none' [-Wunused-command-line-argument]

@sscalpone
Copy link
Member

Neither -fimplicit-none nor -u is supported in flang. It's been reported as flang-compiler/clang#22.

@sscalpone sscalpone added the bug label Sep 1, 2018
@pawosm-arm
Copy link
Collaborator Author

Closing this ticket as contrary to gfortran, Flang compiler rejected wrong code. Such behaviour should be considered as an advantage rather than a bug.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants