]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fortran: PDT - gfortran does not catch F2023:R916 [PR122165]
authorPaul Thomas <pault@gcc.gnu.org>
Wed, 29 Oct 2025 11:06:19 +0000 (11:06 +0000)
committerPaul Thomas <pault@gcc.gnu.org>
Wed, 29 Oct 2025 11:06:19 +0000 (11:06 +0000)
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.

gcc/fortran/primary.cc
gcc/testsuite/gfortran.dg/pdt_64.f03 [new file with mode: 0644]

index 2d2c664f10a30abe451986b7df37bd121d9497e2..0722c76d9e5db857c77d4a7c039b1ce446b6b73f 100644 (file)
@@ -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 (file)
index 0000000..dfa4e3a
--- /dev/null
@@ -0,0 +1,17 @@
+! { 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