aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarald Anlauf <anlauf@gmx.de>2022-06-29 21:36:17 +0200
committerHarald Anlauf <anlauf@gmx.de>2022-06-30 20:46:12 +0200
commit4c233cabbe388a6b8957c1507e129090e9267ceb (patch)
treeec234429c9d62ad37f7f05292bdeca03d8706544
parentd489ec082ea214109ff54071410f8cd00344e654 (diff)
downloadgcc-4c233cabbe388a6b8957c1507e129090e9267ceb.zip
gcc-4c233cabbe388a6b8957c1507e129090e9267ceb.tar.gz
gcc-4c233cabbe388a6b8957c1507e129090e9267ceb.tar.bz2
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. Co-authored-by: Steven G. Kargl <kargl@gcc.gnu.org>
-rw-r--r--gcc/fortran/decl.cc8
-rw-r--r--gcc/testsuite/gfortran.dg/class_58.f902
-rw-r--r--gcc/testsuite/gfortran.dg/class_73.f9017
3 files changed, 26 insertions, 1 deletions
diff --git a/gcc/fortran/decl.cc b/gcc/fortran/decl.cc
index 26ff54d..339f8b1 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 20b601a..fceb575 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 0000000..c11ee38
--- /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