Edit: With respect to the inquiry re: a bug in Intel Fortran in the original post, please see this comment post further below in this thread.
The operative word is “almost”: you have the answer in the error message, “This intrinsic function is invalid in constant expressions.” The standard is rather limiting when it comes to what is allows in constant expressions and the standard defined functions from the intrinsic module ISO_FORTRAN_ENV are not among the permitted ones.
You can try this out first where the restrictions of constant expressions with defining named constants do not apply:
use iso_fortran_env, only: compiler_version
character(len=:), allocatable :: compiled_by
compiled_by = compiler_version()
print *, compiled_by
end
C:\temp>ifort /standard-semantics p.f90
Intel(R) Fortran Intel(R) 64 Compiler Classic for applications running on Intel(R) 64, Version 2021.6.0 Build 20220226_000000
Copyright (C) 1985-2022 Intel Corporation. All rights reserved.Microsoft (R) Incremental Linker Version 14.30.30706.0
Copyright (C) Microsoft Corporation. All rights reserved.-out:p.exe
-subsystem:console
p.objC:\temp>p.exe
Intel(R) Fortran Intel(R) 64 Compiler Classic for applications running on Intel
(R) 64, Version 2021.6.0 Build 20220226_000000