public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
From: Paul Richard Thomas <paul.richard.thomas@gmail.com>
To: "fortran@gcc.gnu.org" <fortran@gcc.gnu.org>,
	gcc-patches <gcc-patches@gcc.gnu.org>
Subject: [Patch, fortran] PR80657 - [7/8/9 Regression] Loop in character function declaration
Date: Sat, 19 May 2018 10:39:00 -0000	[thread overview]
Message-ID: <CAGkQGiJR8V=5DzA=LknU0vYRk1iFvWfAORZYpLJ7qQBBfCWS4w@mail.gmail.com> (raw)

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

I intend to commit this as 'obvious' once the patches for PR82923 and
82275 are out of the way.

Paul

2018-05-19  Paul Thomas  <pault@gcc.gnu.org>

    PR fortran/80657
    * resolve.c (flag_fn_result_spec): Use the 'sym' argument to
    test for self refs to the function result in the character len
    expression. If a self reference is found, emit an error and
    return true.
    (resolve_fntype): Use the function symbol in the calls to the
    above.

2018-05-19  Paul Thomas  <pault@gcc.gnu.org>

    PR fortran/80657
    * gfortran.dg/char_result_18.f90: New test.

[-- Attachment #2: submit.diff --]
[-- Type: text/x-patch, Size: 1917 bytes --]

Index: gcc/fortran/resolve.c
===================================================================
*** gcc/fortran/resolve.c	(revision 260389)
--- gcc/fortran/resolve.c	(working copy)
*************** resolve_equivalence (gfc_equiv *eq)
*** 16217,16223 ****
  
  static bool
  flag_fn_result_spec (gfc_expr *expr,
!                      gfc_symbol *sym ATTRIBUTE_UNUSED,
                       int *f ATTRIBUTE_UNUSED)
  {
    gfc_namespace *ns;
--- 16217,16223 ----
  
  static bool
  flag_fn_result_spec (gfc_expr *expr,
!                      gfc_symbol *sym,
                       int *f ATTRIBUTE_UNUSED)
  {
    gfc_namespace *ns;
*************** flag_fn_result_spec (gfc_expr *expr,
*** 16230,16235 ****
--- 16230,16242 ----
  	if (!ns->parent)
  	  break;
  
+       if (sym == s)
+ 	{
+ 	  gfc_error ("Self reference in character length expression "
+ 		     "for %qs at %L", sym->name, &expr->where);
+ 	  return true;
+ 	}
+ 
        if (!s->fn_result_spec
  	  && s->attr.flavor == FL_PARAMETER)
  	{
*************** resolve_fntype (gfc_namespace *ns)
*** 16312,16318 ****
        }
  
    if (sym->ts.type == BT_CHARACTER)
!     gfc_traverse_expr (sym->ts.u.cl->length, NULL, flag_fn_result_spec, 0);
  }
  
  
--- 16319,16325 ----
        }
  
    if (sym->ts.type == BT_CHARACTER)
!     gfc_traverse_expr (sym->ts.u.cl->length, sym, flag_fn_result_spec, 0);
  }
  
  
Index: gcc/testsuite/gfortran.dg/char_result_18.f90
===================================================================
*** gcc/testsuite/gfortran.dg/char_result_18.f90	(nonexistent)
--- gcc/testsuite/gfortran.dg/char_result_18.f90	(working copy)
***************
*** 0 ****
--- 1,10 ----
+ ! { dg-do compile }
+ !
+ ! Tests the fix for PR80657.
+ !
+ ! Contributed by Vittorio Zecca  <zeccav@gmail.com>
+ !
+ function f(x)
+ implicit character(len(f)) (x) ! { dg-error "Self reference in character length" }
+ character(len(x)) f
+ end

                 reply	other threads:[~2018-05-19 10:39 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='CAGkQGiJR8V=5DzA=LknU0vYRk1iFvWfAORZYpLJ7qQBBfCWS4w@mail.gmail.com' \
    --to=paul.richard.thomas@gmail.com \
    --cc=fortran@gcc.gnu.org \
    --cc=gcc-patches@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).