public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Harald Anlauf <anlauf@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r11-10107] Fortran: error recovery on invalid CLASS(), PARAMETER declarations [PR105243]
Date: Sun,  3 Jul 2022 20:13:44 +0000 (GMT)	[thread overview]
Message-ID: <20220703201344.201CC3851C25@sourceware.org> (raw)

https://gcc.gnu.org/g:5c293d9abc4b14e987a574fc11666809a2b8b8da

commit r11-10107-g5c293d9abc4b14e987a574fc11666809a2b8b8da
Author: Harald Anlauf <anlauf@gmx.de>
Date:   Wed Jun 29 21:36:17 2022 +0200

    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.c (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>
    (cherry picked from commit 4c233cabbe388a6b8957c1507e129090e9267ceb)

Diff:
---
 gcc/fortran/decl.c                     |  8 ++++++++
 gcc/testsuite/gfortran.dg/class_58.f90 |  2 +-
 gcc/testsuite/gfortran.dg/class_73.f90 | 17 +++++++++++++++++
 3 files changed, 26 insertions(+), 1 deletion(-)

diff --git a/gcc/fortran/decl.c b/gcc/fortran/decl.c
index 60f841d0264..c25b53f9772 100644
--- a/gcc/fortran/decl.c
+++ b/gcc/fortran/decl.c
@@ -6181,6 +6181,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


                 reply	other threads:[~2022-07-03 20:13 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220703201344.201CC3851C25@sourceware.org \
    --to=anlauf@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).