Skip to content

Commit 5c4127c

Browse files
committed
fix(gfortran): work around kind type parameter bug
1 parent 8d23cf5 commit 5c4127c

4 files changed

Lines changed: 37 additions & 3 deletions

File tree

include/language-support.F90

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,12 @@
2121
#define HAVE_MULTI_IMAGE_SUPPORT 0
2222
#endif
2323
#endif
24+
25+
#ifndef HAVE_DERIVED_TYPE_KIND_PARAMETERS
26+
! Define whether the compiler has sufficient support for kind type parameters for derived types
27+
#if defined(_CRAYFTN) || defined(__INTEL_COMPILER) || defined(NAGFOR)
28+
#define HAVE_DERIVED_TYPE_KIND_PARAMETERS 1
29+
#else
30+
#define HAVE_DERIVED_TYPE_KIND_PARAMETERS 0
31+
#endif
32+
#endif

src/julienne/julienne_test_diagnosis_m.f90 renamed to src/julienne/julienne_test_diagnosis_m.F90

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
! Copyright (c) 2024-2025, The Regents of the University of California and Sourcery Institute
22
! Terms of use are as specified in LICENSE.txt
3+
4+
#include "language-support.F90"
5+
36
module julienne_test_diagnosis_m
47
!! Define an abstraction for describing test outcomes and diagnostic information
58
use julienne_string_m, only : string_t
@@ -23,10 +26,20 @@ module julienne_test_diagnosis_m
2326

2427
integer, parameter :: default_real = kind(1.), double_precision = kind(1D0)
2528

29+
#if HAVE_DERIVED_TYPE_KIND_PARAMETERS
2630
type operands_t(k)
2731
integer, kind :: k = default_real
2832
real(k) actual, expected
2933
end type
34+
#else
35+
type operands_t
36+
real actual, expected
37+
end type
38+
39+
type double_precision_operands_t
40+
double precision actual, expected
41+
end type
42+
#endif
3043

3144
interface operator(.approximates.)
3245

@@ -39,7 +52,11 @@ pure module function approximates_real(actual, expected) result(operands)
3952
pure module function approximates_double_precision(actual, expected) result(operands)
4053
implicit none
4154
double precision, intent(in) :: actual, expected
55+
#if HAVE_DERIVED_TYPE_KIND_PARAMETERS
4256
type(operands_t(double_precision)) operands
57+
#else
58+
type(double_precision_operands_t) operands
59+
#endif
4360
end function
4461

4562
end interface
@@ -65,7 +82,11 @@ pure module function within_real(operands, tolerance) result(test_diagnosis)
6582

6683
pure module function within_double_precision(operands, tolerance) result(test_diagnosis)
6784
implicit none
85+
#if HAVE_DERIVED_TYPE_KIND_PARAMETERS
6886
type(operands_t(double_precision)), intent(in) :: operands
87+
#else
88+
type(double_precision_operands_t), intent(in) :: operands
89+
#endif
6990
double precision, intent(in) :: tolerance
7091
type(test_diagnosis_t) test_diagnosis
7192
end function

src/julienne/julienne_test_diagnosis_s.F90

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@
1313
end procedure
1414

1515
module procedure approximates_double_precision
16+
#if HAVE_DERIVED_TYPE_KIND_PARAMETERS
1617
operands = operands_t(double_precision)(actual, expected)
18+
#else
19+
operands = double_precision_operands_t(actual, expected)
20+
#endif
1721
end procedure
1822

1923
module procedure equals_expected_integer

test/test_diagnosis_test_m.F90

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ function results() result(test_results)
4848
] )
4949
#else
5050
! Work around missing Fortran 2008 feature: associating a procedure actual argument with a procedure pointer dummy argument:
51-
type(test_diagnosis_t), allocatable :: descriptions(:)
52-
procedure(diagnosis_function_i), pointer :: check_real_approximates_ptr, check_double_approximates, check_integer_equals
51+
type(test_description_t), allocatable :: descriptions(:)
52+
procedure(diagnosis_function_i), pointer :: check_real_approximates_ptr, check_double_approximates_ptr, check_integer_equals_ptr
5353
check_real_approximates_ptr => check_real_approximates
5454
check_double_approximates_ptr => check_double_approximates
5555

@@ -73,7 +73,7 @@ function results() result(test_results)
7373
block
7474
logical substring_in_subject
7575
logical, allocatable :: substring_in_test_diagnosis(:)
76-
type(test_diagnosis_t), allocatable :: matching_descriptions(:)
76+
type(test_description_t), allocatable :: matching_descriptions(:)
7777

7878
substring_in_subject = index(subject(), test_description_substring) /= 0
7979
substring_in_test_diagnosis = descriptions%contains_text(test_description_substring)

0 commit comments

Comments
 (0)