stdlib icon indicating copy to clipboard operation
stdlib copied to clipboard

Provide compiler version and compiler options via stdlib_version

Open awvwgk opened this issue 4 years ago • 1 comments

Would it be useful for this module to also provide compile-time constants of compiler version and options used to build it?

module m
  use iso_fortran_env, only: compiler_version, compiler_options
  character(*), parameter :: stdlib_compiler_version = compiler_version()
  character(*), parameter :: stdlib_compiler_options = compiler_options()
end module m

program p
  use m
  print *, stdlib_compiler_version
  print *, stdlib_compiler_options
end

It works nicely with GFortran, but ifort 2021.3.0 doesn't seem to allow these intrinsic in constant expressions:

$ ifort test.f90 
test.f90(3): error #6263: This intrinsic function is invalid in constant expressions.   [COMPILER_VERSION]
  character(*), parameter :: stdlib_compiler_version = compiler_version()
-------------------------------------------------------^
test.f90(4): error #6263: This intrinsic function is invalid in constant expressions.   [COMPILER_OPTIONS]
  character(*), parameter :: stdlib_compiler_options = compiler_options()
-------------------------------------------------------^
test.f90(8): error #7002: Error in opening the compiled module file.  Check INCLUDE paths.   [M]
  use m
------^
compilation aborted for test.f90 (code 1)

which I think is incorrect. Anyhow, just an idea, something we could tackle in another PR.

Originally posted by @milancurcic in https://github.com/fortran-lang/stdlib/pull/579#pullrequestreview-817149743

awvwgk avatar Nov 27 '21 17:11 awvwgk

Agree this would be nice to have, when a sufficient number of compilers are happy with it.

gareth-nx avatar Nov 28 '21 01:11 gareth-nx