diff mbox series

PR fortran/102956 - PDT KIND and LEN type parameters are mutually exclusive

Message ID trinity-4e000edb-f9e8-4f1d-b016-24247351a1e0-1635277232368@3c-app-gmx-bs16
State New
Headers show
Series PR fortran/102956 - PDT KIND and LEN type parameters are mutually exclusive | expand

Commit Message

Harald Anlauf Oct. 26, 2021, 7:40 p.m. UTC
Dear Fortranners,

we were missing a conflict check for PDT KIND and LEN type parameters:


F2018: 7.5.3.1  Type parameter definition statement

R732  type-param-def-stmt is
      integer-type-spec, type-param-attr-spec :: type-param-decl-list

R734  type-param-attr-spec  is KIND or LEN

(3) The type-param-attr-spec explicitly specifies whether a type parameter is a kind parameter or a length parameter.

Thus the KIND and LEN attributes are mutually exclusive.


The attached trivial patch remedies that.

Regtested on x86_64-pc-linux-gnu.  OK for mainline?

Thanks,
Harald

Comments

Tobias Burnus Oct. 26, 2021, 7:56 p.m. UTC | #1
On 26.10.21 21:40, Harald Anlauf via Fortran wrote:

> we were missing a conflict check for PDT KIND and LEN type parameters:
>
>
> F2018: 7.5.3.1  Type parameter definition statement
>
> R732  type-param-def-stmt is
>        integer-type-spec, type-param-attr-spec :: type-param-decl-list
>
> R734  type-param-attr-spec  is KIND or LEN
>
> (3) The type-param-attr-spec explicitly specifies whether a type parameter is a kind parameter or a length parameter.
>
> Thus the KIND and LEN attributes are mutually exclusive.
>
>
> The attached trivial patch remedies that.
>
> Regtested on x86_64-pc-linux-gnu.  OK for mainline?

LGTM, thanks.

Tobias

-----------------
Siemens Electronic Design Automation GmbH; Anschrift: Arnulfstraße 201, 80634 München; Gesellschaft mit beschränkter Haftung; Geschäftsführer: Thomas Heurung, Frank Thürauf; Sitz der Gesellschaft: München; Registergericht München, HRB 106955
diff mbox series

Patch

Fortran: [PDT] KIND and LEN type parameters are mutually exclusive

gcc/fortran/ChangeLog:

	PR fortran/102956
	* symbol.c (gfc_check_conflict): Add conflict check for PDT KIND
	and LEN type parameters.

gcc/testsuite/ChangeLog:

	PR fortran/102956
	* gfortran.dg/pdt_32.f03: New test.

diff --git a/gcc/fortran/symbol.c b/gcc/fortran/symbol.c
index 2c4acd5abe1..c77f3f84962 100644
--- a/gcc/fortran/symbol.c
+++ b/gcc/fortran/symbol.c
@@ -720,6 +720,7 @@  gfc_check_conflict (symbol_attribute *attr, const char *name, locus *where)
   conf (pdt_len, pointer)
   conf (pdt_len, dimension)
   conf (pdt_len, codimension)
+  conf (pdt_len, pdt_kind)

   if (attr->access == ACCESS_PRIVATE)
     {
diff --git a/gcc/testsuite/gfortran.dg/pdt_32.f03 b/gcc/testsuite/gfortran.dg/pdt_32.f03
new file mode 100644
index 00000000000..f8d40410828
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pdt_32.f03
@@ -0,0 +1,17 @@ 
+! { dg-do compile }
+! PR fortran/102956
+! PDT KIND and LEN type parameters are mutually exclusive (F2018:R734)
+!
+module m
+  type :: good_pdt (k,l)
+     integer, kind           :: k = 1
+     integer, len            :: l = 1
+     character(kind=k,len=l) :: c
+  end type good_pdt
+
+  type :: bad_pdt (k,l)               ! { dg-error "does not have a component" }
+     integer, kind, len      :: k = 1 ! { dg-error "attribute conflicts with" }
+     integer, len, kind      :: l = 1 ! { dg-error "attribute conflicts with" }
+     character(kind=k,len=l) :: c     ! { dg-error "has not been declared" }
+  end type bad_pdt
+end