How to detect uninitialized arguments?

Yes, for example epsilon(x). As a user I would not want the compiler to warn me here. But I think a compiler can figure this out correctly when the value of x is needed, and when not.

Regarding undefine x, can you give a short example that you have in mind? So far I couldn’t figure out one where the compiler couldn’t (in principle) figure out how to optimize equally well without it.

It is syntactic sugar, as I admitted. The intention is to alert the compiler that it is profitable to note the fact of undefinition in its analysis. Original FORTRAN, after all, had FREQUENCY statement. Most compilers I try are supremely uninterested in the undefinition of INTENT(OUT) variables and produce code that is difficult to make sense of.

Program akimbo
  Implicit None
  Real :: rnd
  Integer :: az, xw, h

  Call RANDOM_NUMBER(rnd)
  h = INT(700*rnd)
  xw = 42
  Call test(az, xw)
  Print '(I12)',xw
Contains
  Subroutine test(a, x)
    Integer, Intent (Out) :: a
    Integer, Intent (Inout) :: x

    If (even(h+1)) a = 666
    If (even(h)) x = a
  End Subroutine
  Logical Pure Function even(h)
    Integer, Intent (In) :: h

    even = MOD(h, 2) == 0
  End Function
End Program

It is correct to produce the same program as

Print '(10X,"42")'; End
1 Like

@certik said “I think you never want an uninitialized variable in a code” but this 4-line program does something useful with its uninitialized x. These compilers compiled and ran it: gfortran, AMD flang, ifx, ifort, lfortran, and g95, which warned that x was used but not set.

  implicit none
  real x
  print *,huge(x)
end program

@Harper yes, your example is the same as my comment above about this exact case.