Skip to content

Commit

Permalink
Merge pull request #25 from nncarlson/issue24
Browse files Browse the repository at this point in the history
Workaround for gfortran bug (resolves #24)
  • Loading branch information
nncarlson committed Mar 31, 2021
2 parents 0c9d35f + ba91574 commit f17df95
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ elseif(CMAKE_Fortran_COMPILER_ID MATCHES NAG)
"your version is ${CMAKE_Fortran_COMPILER_VERSION}")
endif()
elseif(CMAKE_Fortran_COMPILER_ID MATCHES GNU)
list(APPEND Fortran_COMPILE_DEFINITIONS GNU_PR93762)
list(APPEND Fortran_COMPILE_DEFINITIONS NO_2008_GENERIC_RESOLUTION)
if((CMAKE_Fortran_COMPILER_VERSION VERSION_GREATER_EQUAL "10.1") AND
(CMAKE_Fortran_COMPILER_VERSION VERSION_LESS "10.2"))
Expand Down
8 changes: 8 additions & 0 deletions src/parameter_list_type.F90
Original file line number Diff line number Diff line change
Expand Up @@ -434,10 +434,18 @@ subroutine error (errmsg_, stat, errmsg)
use,intrinsic :: iso_fortran_env, only: error_unit
character(*), intent(in) :: errmsg_
integer, intent(out), optional :: stat
#ifdef GNU_PR93762
character(:), allocatable :: errmsg
#else
character(:), allocatable, intent(out), optional :: errmsg
#endif
if (present(stat)) then
stat = 1
#ifdef GNU_PR93762
errmsg = errmsg_
#else
if (present(errmsg)) errmsg = errmsg_
#endif
else
write(error_unit,'(a)') 'ERROR: ' // errmsg_
stop 1
Expand Down
15 changes: 9 additions & 6 deletions test/parameter_list_type/test_parameter_list_type.F90
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ subroutine test_basic

type(parameter_list) :: p
integer ::stat
character(:), allocatable :: errmsg

!! A derived type
type point; real x, y; end type
Expand Down Expand Up @@ -89,12 +90,12 @@ subroutine test_basic
if (.not.p%is_matrix('bah')) call write_fail ('test_basic failed test 22')

!! Replace the value of a parameter; different rank -- should fail
call p%set ('foo', [1,2], stat=stat)
call p%set ('foo', [1,2], stat=stat, errmsg=errmsg)
if (stat == 0) call write_fail ('test_basic failed test 23')
if (p%count() /= 4) call write_fail ('test_basic failed test 24')

!! Replace the value of a parameter; same rank -- should succeed.
call p%set ('bar', [1,2], stat=stat)
call p%set ('bar', [1,2], stat=stat, errmsg=errmsg)
if (stat /= 0) call write_fail ('test_basic failed test 25')
if (p%count() /= 4) call write_fail ('test_basic failed test 26')

Expand Down Expand Up @@ -449,12 +450,13 @@ subroutine test_overwrite
character(:), allocatable :: c, carray(:), cmatrix(:,:)
type point; real x, y; end type
integer :: stat
character(:), allocatable :: errmsg
class(*), allocatable :: scalar, vector(:), matrix(:,:)

call p%set ('foo', 13)

!! Overwrite with different rank; should fail
call p%set ('foo', [1], stat=stat)
call p%set ('foo', [1], stat=stat, errmsg=errmsg)
if (stat == 0) call write_fail ('test_overwrite failed test 1')

!! Overwrite with different values/types.
Expand All @@ -476,7 +478,7 @@ subroutine test_overwrite
call p%set ('bar', [13])

!! Overwrite with different rank; should fail
call p%set ('bar', 1, stat=stat)
call p%set ('bar', 1, stat=stat, errmsg=errmsg)
if (stat == 0) call write_fail ('test_overwrite failed test 6')

!! Overwrite with different values/types.
Expand All @@ -498,7 +500,7 @@ subroutine test_overwrite
call p%set ('biz', reshape([13],shape=[1,1]))

!! Overwrite with different rank; should fail
call p%set ('biz', [1], stat=stat)
call p%set ('biz', [1], stat=stat, errmsg=errmsg)
if (stat == 0) call write_fail ('test_overwrite failed test 11')

!! Overwrite with different values/types.
Expand Down Expand Up @@ -528,6 +530,7 @@ subroutine test_sublists
type(parameter_list) :: p
type(parameter_list), pointer :: sl, sla, slb
integer :: stat
character(:), allocatable :: errmsg

!! Create a sublist parameter and add a parameter to the sublist.
sla => p%sublist('A')
Expand All @@ -540,7 +543,7 @@ subroutine test_sublists
if (.not.p%is_parameter('A')) call write_fail ('test_sublists failed test 4')

!! Try to use sublist with an existing non-sublist parameter; should fail.
slb => sla%sublist('foo', stat)
slb => sla%sublist('foo', stat, errmsg=errmsg)
if (stat == 0) call write_fail ('test_sublists failed test 5')

!! Create a sublist parameter of the sublist.
Expand Down

0 comments on commit f17df95

Please sign in to comment.