2025-10-29 Paul Thomas <pault@gcc.gnu.org>
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.
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)
--- /dev/null
+! { dg-do compile }
+!
+! Test the fix for PR122165.
+!
+! Contributed by Steve Kargl <kargls@comcast.net>
+!
+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