From: Janus Weil <janus@gcc.gnu.org>
To: gfortran <fortran@gcc.gnu.org>, gcc-patches <gcc-patches@gcc.gnu.org>
Subject: [Patch, Fortran, F03] PR 80046: Explicit interface required: pointer argument
Date: Wed, 29 Mar 2017 20:35:00 -0000 [thread overview]
Message-ID: <CAKwh3qgF=J+qjWZto850vNehGaF9yyUODBqtr2-9WFv=1RRfjQ@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 576 bytes --]
Hi all,
here is a patch that enhances the diagnostics for procedure-pointer
assignments, so that procedure-pointer components that need an
explicit interface are correctly rejected.
Regtests cleanly on x86_64-linux-gnu. Ok for trunk?
Cheers,
Janus
2017-03-29 Janus Weil <janus@gcc.gnu.org>
PR fortran/80046
* expr.c (gfc_check_pointer_assign): Check if procedure pointer
components in a pointer assignment need an explicit interface.
2017-03-29 Janus Weil <janus@gcc.gnu.org>
PR fortran/80046
* gfortran.dg/proc_ptr_comp_48.f90: New test case.
[-- Attachment #2: pr80046.diff --]
[-- Type: text/plain, Size: 1875 bytes --]
Index: gcc/fortran/expr.c
===================================================================
--- gcc/fortran/expr.c (revision 246573)
+++ gcc/fortran/expr.c (working copy)
@@ -3595,25 +3595,41 @@ gfc_check_pointer_assign (gfc_expr *lvalue, gfc_ex
return false;
}
- if (s1 == s2 || !s1 || !s2)
- return true;
-
/* F08:7.2.2.4 (4) */
- if (s1->attr.if_source == IFSRC_UNKNOWN
- && gfc_explicit_interface_required (s2, err, sizeof(err)))
+ if (s2 && gfc_explicit_interface_required (s2, err, sizeof(err)))
{
- gfc_error ("Explicit interface required for %qs at %L: %s",
- s1->name, &lvalue->where, err);
- return false;
+ if (comp1 && !s1)
+ {
+ gfc_error ("Explicit interface required for component %qs at %L: %s",
+ comp1->name, &lvalue->where, err);
+ return false;
+ }
+ else if (s1->attr.if_source == IFSRC_UNKNOWN)
+ {
+ gfc_error ("Explicit interface required for %qs at %L: %s",
+ s1->name, &lvalue->where, err);
+ return false;
+ }
}
- if (s2->attr.if_source == IFSRC_UNKNOWN
- && gfc_explicit_interface_required (s1, err, sizeof(err)))
+ if (s1 && gfc_explicit_interface_required (s1, err, sizeof(err)))
{
- gfc_error ("Explicit interface required for %qs at %L: %s",
- s2->name, &rvalue->where, err);
- return false;
+ if (comp2 && !s2)
+ {
+ gfc_error ("Explicit interface required for component %qs at %L: %s",
+ comp2->name, &rvalue->where, err);
+ return false;
+ }
+ else if (s2->attr.if_source == IFSRC_UNKNOWN)
+ {
+ gfc_error ("Explicit interface required for %qs at %L: %s",
+ s2->name, &rvalue->where, err);
+ return false;
+ }
}
+ if (s1 == s2 || !s1 || !s2)
+ return true;
+
if (!gfc_compare_interfaces (s1, s2, name, 0, 1,
err, sizeof(err), NULL, NULL))
{
[-- Attachment #3: proc_ptr_comp_48.f90 --]
[-- Type: text/x-fortran, Size: 1292 bytes --]
! { dg-do compile }
!
! PR 80046: [F03] Explicit interface required: pointer argument
!
! Contributed by Joachim Herb <joachim.herb@gmx.de>
program p
implicit none
type :: Node_t
procedure(NodeCloner), nopass, pointer :: cloneProc => NULL()
procedure(), nopass, pointer :: noIfc => NULL()
end type
interface
subroutine NodeCloner( tgt, src )
import Node_t
type(Node_t), pointer, intent(out) :: tgt
type(Node_t), intent(in) :: src
end subroutine
end interface
type(Node_t) :: node
procedure(NodeCloner), pointer :: cloneNode
procedure(), pointer :: noIfc
cloneNode => node%noIfc ! { dg-error "Explicit interface required" }
node%noIfc => cloneNode ! { dg-error "Explicit interface required" }
noIfc => node%cloneProc ! { dg-error "Explicit interface required" }
node%cloneProc => noIfc ! { dg-error "Explicit interface required" }
node%cloneProc => node%noIfc ! { dg-error "Explicit interface required" }
node%noIfc => node%cloneProc ! { dg-error "Explicit interface required" }
! the following cases are legal
node%noIfc => node%noIfc
node%cloneProc => node%cloneProc
cloneNode => node%cloneProc
node%cloneProc => cloneNode
noIfc => node%noIfc
node%noIfc => noIfc
end
next reply other threads:[~2017-03-29 20:25 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-29 20:35 Janus Weil [this message]
2017-04-07 16:51 ` Janus Weil
2017-04-09 10:40 ` Paul Richard Thomas
2017-04-10 20:29 ` Janus Weil
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='CAKwh3qgF=J+qjWZto850vNehGaF9yyUODBqtr2-9WFv=1RRfjQ@mail.gmail.com' \
--to=janus@gcc.gnu.org \
--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).