public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] PR fortran/102956 - PDT KIND and LEN type parameters are mutually exclusive
@ 2021-10-26 19:40 Harald Anlauf
  2021-10-26 19:56 ` Tobias Burnus
  0 siblings, 1 reply; 2+ messages in thread
From: Harald Anlauf @ 2021-10-26 19:40 UTC (permalink / raw)
  To: fortran, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 579 bytes --]

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


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: pr102956.diff --]
[-- Type: text/x-patch, Size: 1593 bytes --]

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] PR fortran/102956 - PDT KIND and LEN type parameters are mutually exclusive
  2021-10-26 19:40 [PATCH] PR fortran/102956 - PDT KIND and LEN type parameters are mutually exclusive Harald Anlauf
@ 2021-10-26 19:56 ` Tobias Burnus
  0 siblings, 0 replies; 2+ messages in thread
From: Tobias Burnus @ 2021-10-26 19:56 UTC (permalink / raw)
  To: Harald Anlauf, fortran, gcc-patches

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-10-26 19:56 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-26 19:40 [PATCH] PR fortran/102956 - PDT KIND and LEN type parameters are mutually exclusive Harald Anlauf
2021-10-26 19:56 ` Tobias Burnus

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).