* [PATCH] Fortran: error recovery on invalid CLASS(), PARAMETER declarations [PR105243]
@ 2022-06-29 19:54 Harald Anlauf
2022-06-30 9:58 ` Tobias Burnus
0 siblings, 1 reply; 4+ messages in thread
From: Harald Anlauf @ 2022-06-29 19:54 UTC (permalink / raw)
To: fortran, gcc-patches
[-- Attachment #1: Type: text/plain, Size: 644 bytes --]
Dear all,
a CLASS entity cannot have the PARAMETER attribute.
This is detected in some situations, but in others
we ICE because we never reach the existing check.
Adding a similar check when handling the declaration
improves error recovery.
The initial patch is by Steve. I adjusted and moved
it slightly so that it also handles CLASS(*)
(unlimited polymorphic) at the same time.
Regtested on x86_64-pc-linux-gnu. OK for mainline?
This patch actually addresses multiple PRs, some of
which are marked as regressions. As I consider the
patch safe, I would like to backport to open branches
as far as it seems appropriate.
Thanks,
Harald
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Fortran-error-recovery-on-invalid-CLASS-PARAMETER-de.patch --]
[-- Type: text/x-patch, Size: 2960 bytes --]
From e0d5aeadd218f21e450db6601956691293210156 Mon Sep 17 00:00:00 2001
From: Harald Anlauf <anlauf@gmx.de>
Date: Wed, 29 Jun 2022 21:36:17 +0200
Subject: [PATCH] Fortran: error recovery on invalid CLASS(), PARAMETER
declarations [PR105243]
gcc/fortran/ChangeLog:
PR fortran/103137
PR fortran/103138
PR fortran/103693
PR fortran/105243
* decl.cc (gfc_match_data_decl): Reject CLASS entity declaration
when it is given the PARAMETER attribute.
gcc/testsuite/ChangeLog:
PR fortran/103137
PR fortran/103138
PR fortran/103693
PR fortran/105243
* gfortran.dg/class_58.f90: Fix test.
* gfortran.dg/class_73.f90: New test.
---
gcc/fortran/decl.cc | 8 ++++++++
gcc/testsuite/gfortran.dg/class_58.f90 | 2 +-
gcc/testsuite/gfortran.dg/class_73.f90 | 17 +++++++++++++++++
3 files changed, 26 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/gfortran.dg/class_73.f90
diff --git a/gcc/fortran/decl.cc b/gcc/fortran/decl.cc
index 26ff54d4684..339f8b15035 100644
--- a/gcc/fortran/decl.cc
+++ b/gcc/fortran/decl.cc
@@ -6262,6 +6262,14 @@ gfc_match_data_decl (void)
goto cleanup;
}
+ /* F2018:C708. */
+ if (current_ts.type == BT_CLASS && current_attr.flavor == FL_PARAMETER)
+ {
+ gfc_error ("CLASS entity at %C cannot have the PARAMETER attribute");
+ m = MATCH_ERROR;
+ goto cleanup;
+ }
+
if (current_ts.type == BT_CLASS
&& current_ts.u.derived->attr.unlimited_polymorphic)
goto ok;
diff --git a/gcc/testsuite/gfortran.dg/class_58.f90 b/gcc/testsuite/gfortran.dg/class_58.f90
index 20b601a2f51..fceb575432d 100644
--- a/gcc/testsuite/gfortran.dg/class_58.f90
+++ b/gcc/testsuite/gfortran.dg/class_58.f90
@@ -9,5 +9,5 @@ subroutine s
end type
class(t), parameter :: x = t() ! { dg-error "cannot have the PARAMETER attribute" }
class(t), parameter :: y = x ! { dg-error "cannot have the PARAMETER attribute" }
- class(t) :: z = x ! { dg-error "must be dummy, allocatable or pointer" }
+ class(t) :: z = t() ! { dg-error "must be dummy, allocatable or pointer" }
end
diff --git a/gcc/testsuite/gfortran.dg/class_73.f90 b/gcc/testsuite/gfortran.dg/class_73.f90
new file mode 100644
index 00000000000..c11ee38c086
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/class_73.f90
@@ -0,0 +1,17 @@
+! { dg-do compile }
+! Error recovery on invalid CLASS(), PARAMETER declarations
+! PR fortran/103137
+! PR fortran/103138
+! PR fortran/103693
+! PR fortran/105243
+! Contributed by G.Steinmetz
+
+program p
+ type t
+ character(3) :: c = '(a)'
+ end type
+ class(t), parameter :: x = 1. ! { dg-error "PARAMETER attribute" }
+ class(*), parameter :: y = t() ! { dg-error "PARAMETER attribute" }
+ class(*), parameter :: z = 1 ! { dg-error "PARAMETER attribute" }
+ print x%c ! { dg-error "Syntax error" }
+end
--
2.35.3
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Fortran: error recovery on invalid CLASS(), PARAMETER declarations [PR105243]
2022-06-29 19:54 [PATCH] Fortran: error recovery on invalid CLASS(), PARAMETER declarations [PR105243] Harald Anlauf
@ 2022-06-30 9:58 ` Tobias Burnus
2022-06-30 19:52 ` Harald Anlauf
0 siblings, 1 reply; 4+ messages in thread
From: Tobias Burnus @ 2022-06-30 9:58 UTC (permalink / raw)
To: Harald Anlauf, fortran, gcc-patches
Dear Harald, dear all,
On 29.06.22 21:54, Harald Anlauf via Fortran wrote:
> a CLASS entity cannot have the PARAMETER attribute.
> This is detected in some situations, but in others
> we ICE because we never reach the existing check.
> Adding a similar check when handling the declaration
> improves error recovery.
>
> The initial patch is by Steve. I adjusted and moved
> it slightly so that it also handles CLASS(*)
> (unlimited polymorphic) at the same time.
Shouldn't you then also acknowledge him, e.g. via Co-authored-by?
> Regtested on x86_64-pc-linux-gnu. OK for mainline?
OK. Thanks for the patch!
> This patch actually addresses multiple PRs, some of
> which are marked as regressions. As I consider the
> patch safe, I would like to backport to open branches
> as far as it seems appropriate.
Fine with me.
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] 4+ messages in thread
* Re: [PATCH] Fortran: error recovery on invalid CLASS(), PARAMETER declarations [PR105243]
2022-06-30 9:58 ` Tobias Burnus
@ 2022-06-30 19:52 ` Harald Anlauf
2022-06-30 19:52 ` Harald Anlauf
0 siblings, 1 reply; 4+ messages in thread
From: Harald Anlauf @ 2022-06-30 19:52 UTC (permalink / raw)
To: fortran; +Cc: gcc-patches
Hi Tobias,
Am 30.06.22 um 11:58 schrieb Tobias Burnus:
>> The initial patch is by Steve. I adjusted and moved
>> it slightly so that it also handles CLASS(*)
>> (unlimited polymorphic) at the same time.
> Shouldn't you then also acknowledge him, e.g. via Co-authored-by?
yeah, I noticed that right after submitting the mail
and immediately amended the commit message. Pushed as
https://gcc.gnu.org/g:4c233cabbe388a6b8957c1507e129090e9267ceb
Thanks,
Harald
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] Fortran: error recovery on invalid CLASS(), PARAMETER declarations [PR105243]
2022-06-30 19:52 ` Harald Anlauf
@ 2022-06-30 19:52 ` Harald Anlauf
0 siblings, 0 replies; 4+ messages in thread
From: Harald Anlauf @ 2022-06-30 19:52 UTC (permalink / raw)
To: Tobias Burnus, fortran, gcc-patches
Hi Tobias,
Am 30.06.22 um 11:58 schrieb Tobias Burnus:
>> The initial patch is by Steve. I adjusted and moved
>> it slightly so that it also handles CLASS(*)
>> (unlimited polymorphic) at the same time.
> Shouldn't you then also acknowledge him, e.g. via Co-authored-by?
yeah, I noticed that right after submitting the mail
and immediately amended the commit message. Pushed as
https://gcc.gnu.org/g:4c233cabbe388a6b8957c1507e129090e9267ceb
Thanks,
Harald
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-06-30 19:52 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-29 19:54 [PATCH] Fortran: error recovery on invalid CLASS(), PARAMETER declarations [PR105243] Harald Anlauf
2022-06-30 9:58 ` Tobias Burnus
2022-06-30 19:52 ` Harald Anlauf
2022-06-30 19:52 ` Harald Anlauf
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).