public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
From: Harald Anlauf <anlauf@gmx.de>
To: Paul Richard Thomas <paul.richard.thomas@gmail.com>,
	"fortran@gcc.gnu.org" <fortran@gcc.gnu.org>,
	gcc-patches <gcc-patches@gcc.gnu.org>
Cc: "Steven G. Kargl" <kargl@gcc.gnu.org>
Subject: Re: [Patch, fortran] PR97122 - Spurious FINAL ... must be in the specification part of a MODULE
Date: Tue, 9 May 2023 20:24:16 +0200	[thread overview]
Message-ID: <9b573e6c-52e0-ce7c-6ae4-9b21a55525e9@gmx.de> (raw)
In-Reply-To: <CAGkQGi+jrPoiz2m0PYSSRKDy0Rxyv9sw=3hMeK1OrpS8HdRRgg@mail.gmail.com>

Hi Paul,

On 5/9/23 17:51, Paul Richard Thomas via Gcc-patches wrote:
> Hi All,
>
> Thanks to Steve Kargl for the fix. It caused finalize_8.f03 to fail because
> this testcase checked that finalizable derived types could not be specified
> in a submodule. I have replaced the original test with a test of the patch.
>
> Thanks also to Malcolm Cohen for guidance on this.
>
> OK for trunk?

the patch looks good to me.  However:

@@ -11637,8 +11637,9 @@ gfc_match_final_decl (void)
    block = gfc_state_stack->previous->sym;
    gcc_assert (block);

-  if (!gfc_state_stack->previous || !gfc_state_stack->previous->previous
-      || gfc_state_stack->previous->previous->state != COMP_MODULE)
+  if (gfc_state_stack->previous->previous
+      && gfc_state_stack->previous->previous->state != COMP_MODULE
+      && gfc_state_stack->previous->previous->state != COMP_SUBMODULE)
      {
        gfc_error ("Derived type declaration with FINAL at %C must be in
the"
                  " specification part of a MODULE");

I am wondering if we should keep the protection against a potential
NULL pointer dereference (i.e. gfc_state_stack->previous == NULL) for
possibly invalid code.  I have failed to produce a simple testcase,
but others may have "better" ideas.

I'll leave it to you to amend the patch or leave as is.

Thanks,
Harald


> Paul
>
> Fortran: Allow declaration of finalizable DT in a submodule [PR97122]
>
> 2023-05-09  Paul Thomas  <pault@gcc.gnu.org>
>     Steven G. Kargl  <kargl@gcc.gnu.org>
>
> gcc/fortran
> PR fortran/97122
> * decl.cc (variable_decl): Clean up white space issues.
> (gfc_match_final_decl): Declaration of finalizable derived type
> is allowed in a submodule.
>
> gcc/testsuite/
> PR fortran/97122
> * gfortran.dg/finalize_8.f03 : Replace testcase that checks
> declaration of finalizable derived types in submodules works.


  reply	other threads:[~2023-05-09 18:24 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-05-09 15:51 Paul Richard Thomas
2023-05-09 18:24 ` Harald Anlauf [this message]
2023-05-09 18:29   ` Steve Kargl
2023-05-09 18:35     ` Harald Anlauf
2023-05-09 18:44       ` Steve Kargl

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=9b573e6c-52e0-ce7c-6ae4-9b21a55525e9@gmx.de \
    --to=anlauf@gmx.de \
    --cc=fortran@gcc.gnu.org \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=kargl@gcc.gnu.org \
    --cc=paul.richard.thomas@gmail.com \
    /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).