From: Paul Thomas Date: Wed, 29 Oct 2025 11:06:19 +0000 (+0000) Subject: Fortran: PDT - gfortran does not catch F2023:R916 [PR122165] X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fe7827c25a4e0965f0600d026448c1d73ca107de;p=thirdparty%2Fgcc.git Fortran: PDT - gfortran does not catch F2023:R916 [PR122165] 2025-10-29 Paul Thomas 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 --git a/gcc/fortran/primary.cc b/gcc/fortran/primary.cc index 2d2c664f10a..0722c76d9e5 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 00000000000..dfa4e3aaa1f --- /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 +! +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