This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug fortran/33095] New: MAX with optional arguments gives run-time error


This is a fallout from PR31198.

Using
   a = MAX(1,2, a1, a2)
where a1 and a2 are optional arguments: If both a1 and a2 are not present,
gfortran gives a bogus run-time error message:

Fortran runtime error: Second argument of 'max' intrinsic should be present

Looking at the dump, gfortran optimized the second argument away:

  MAX(2,a1,a2)

if a1 is now not present ...

Fortran 2003:
13.7.71 MAX (A1, A2 [, A3, ...])
13.7.76 MIN (A1, A2 [, A3, ...])
Fortran 95:
13.14.64 MAX (A1, A2 [, A3, ...])
13.14.69 MIN (A1, A2 [, A3, ...])
See also:
http://groups.google.com/group/comp.lang.fortran/msg/be6db97903228689

Test case (from c.l.f):

  PROGRAM testoptarg
    PRINT *, m1(3,4)
    PRINT *, m1(3)
    PRINT *, m1() ! gives the run-time error
  CONTAINS
    INTEGER FUNCTION m1(a1,a2)
      INTEGER, OPTIONAL, INTENT(IN) :: a1,a2
      m1 = max(1, 2, a1, a2)
    END FUNCTION m1
  END PROGRAM testoptarg


-- 
           Summary: MAX with optional arguments gives run-time error
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Keywords: rejects-valid
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: burnus at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=33095


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]