Scheduled Downtime
On Friday 21 April 2023 @ 5pm MT, this website will be down for maintenance and expected to return online the morning of 24 April 2023 at the latest

A bug with recent gfortran compiler

satjemkes

New member
At several locations a subroutine is defined with optional variables. I the executable part of the subroutine, then this optional variable is used in for instance a decision. Unfortunately the optional variable is not set if not provided in the call to the subroutine. then the code will break
solution is to add the value attribute to the optional variable
an example

PROGRAM PDEFAULT
REAL :: a
REAL :: b
a = 4
b = 2
CALL SUB (a,b)
CALL SUB(a,b,.TRUE.)

CONTAINS
SUBROUTINE SUB(a, b, VAL)
REAL, INTENT(IN) :: a, b
logical, OPTIONAL, VALUE:: VAL

IF (.NOT. PRESENT(val) .OR. (PRESENT(val) .AND. (.NOT. val))) THEN
WRITE(*,*) VAL
endif

write (*,*) a*b

END SUBROUTINE SUB

END PROGRAM PDEFAULT

This code will run successfully on ubuntu 22.03 using up to date gfortran compiler
removing the "value" i the definition of the logical VAL will break the code.
you can test this using your favorite compiler.

The construct in the subroutine is used at several locations in selected modules.
 
Top