https://gcc.gnu.org/g:fe7827c25a4e0965f0600d026448c1d73ca107de
commit r16-4706-gfe7827c25a4e0965f0600d026448c1d73ca107de Author: Paul Thomas <[email protected]> Date: Wed Oct 29 11:06:19 2025 +0000 Fortran: PDT - gfortran does not catch F2023:R916 [PR122165] 2025-10-29 Paul Thomas <[email protected]> gcc/fortran PR fortran/122165 * primary.cc (gfc_match_varspec): If the previous component ref was a type specification parameter, a type inquiry ref cannot follow. gcc/testsuite PR fortran/122165 * gfortran.dg/pdt_64.f03: New test. Diff: --- gcc/fortran/primary.cc | 8 ++++++++ gcc/testsuite/gfortran.dg/pdt_64.f03 | 17 +++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/gcc/fortran/primary.cc b/gcc/fortran/primary.cc index 2d2c664f10a3..0722c76d9e5d 100644 --- a/gcc/fortran/primary.cc +++ b/gcc/fortran/primary.cc @@ -2690,6 +2690,14 @@ gfc_match_varspec (gfc_expr *primary, int equiv_flag, bool sub_flag, else component = NULL; + if (previous && inquiry + && (previous->attr.pdt_kind || previous->attr.pdt_len)) + { + gfc_error_now ("R901: A type parameter ref is not a designtor and " + "cannot be followed by the type inquiry ref at %C"); + return MATCH_ERROR; + } + if (intrinsic && !inquiry) { if (previous) diff --git a/gcc/testsuite/gfortran.dg/pdt_64.f03 b/gcc/testsuite/gfortran.dg/pdt_64.f03 new file mode 100644 index 000000000000..dfa4e3aaa1fc --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pdt_64.f03 @@ -0,0 +1,17 @@ +! { dg-do compile } +! +! Test the fix for PR122165. +! +! Contributed by Steve Kargl <[email protected]> +! +program foo + implicit none + type dt(k,l) + integer(8), len :: k = 1 + integer(8), KIND :: l = 1 + character(k) :: arr + end type + type(dt(:)), allocatable :: d1 + if (d1%k%kind /= 8) stop 1 ! { dg-error "cannot be followed by the type inquiry ref" } + if (d1%l%kind /= 8) stop 2 ! { dg-error "cannot be followed by the type inquiry ref" } +end
