public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Janus Weil <janus@gcc.gnu.org>
To: gfortran <fortran@gcc.gnu.org>, gcc-patches <gcc-patches@gcc.gnu.org>
Subject: [Patch, Fortran] PR 41719: [OOP] invalid: Intrinsic assignment  	involving polymorphic variables
Date: Fri, 16 Oct 2009 20:58:00 -0000	[thread overview]
Message-ID: <854832d40910161346g62f3a412k2fe7c71d5b7461f5@mail.gmail.com> (raw)

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

Hi all,

here is a small patch which fixes this PR (rather obvious). It was
successfully regtested on x86_64-unknown-linux-gnu.

As suggested by Tobias in comment #6, I'm ignoring the F08 std on this
matter for now, and just stick to F03.

Ok for trunk?

Cheers,
Janus



2009-10-16  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/41719
	* resolve.c (resolve_ordinary_assign): Reject intrinsic assignments
	to polymorphic variables.


2009-10-16  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/41719
	* gfortran.dg/class_5.f03: New test case.
	* gfortran.dg/typebound_operator_2.f03: Fixing invalid test case.
	* gfortran.dg/typebound_operator_4.f03: Ditto.

[-- Attachment #2: pr41719.diff --]
[-- Type: text/x-diff, Size: 1772 bytes --]

Index: gcc/testsuite/gfortran.dg/typebound_operator_2.f03
===================================================================
--- gcc/testsuite/gfortran.dg/typebound_operator_2.f03	(Revision 152915)
+++ gcc/testsuite/gfortran.dg/typebound_operator_2.f03	(Arbeitskopie)
@@ -50,7 +50,6 @@ CONTAINS
   LOGICAL FUNCTION func (me, b) ! { dg-error "must be a SUBROUTINE" }
     CLASS(t), INTENT(OUT) :: me
     CLASS(t), INTENT(IN) :: b
-    me = t ()
     func = .TRUE.
   END FUNCTION func
 
Index: gcc/testsuite/gfortran.dg/typebound_operator_4.f03
===================================================================
--- gcc/testsuite/gfortran.dg/typebound_operator_4.f03	(Revision 152915)
+++ gcc/testsuite/gfortran.dg/typebound_operator_4.f03	(Arbeitskopie)
@@ -37,7 +37,7 @@ CONTAINS
   PURE SUBROUTINE assign_int (dest, from)
     CLASS(myint), INTENT(OUT) :: dest
     INTEGER, INTENT(IN) :: from
-    dest = myint (from)
+    dest%value = from
   END SUBROUTINE assign_int
 
   TYPE(myreal) FUNCTION add_real (a, b)
@@ -49,7 +49,7 @@ CONTAINS
   SUBROUTINE assign_real (dest, from)
     CLASS(myreal), INTENT(OUT) :: dest
     REAL, INTENT(IN) :: from
-    dest = myreal (from)
+    dest%value = from
   END SUBROUTINE assign_real
 
   SUBROUTINE in_module ()
Index: gcc/fortran/resolve.c
===================================================================
--- gcc/fortran/resolve.c	(Revision 152915)
+++ gcc/fortran/resolve.c	(Arbeitskopie)
@@ -7629,6 +7629,14 @@ resolve_ordinary_assign (gfc_code *code, gfc_names
 	}
     }
 
+  /* F03:7.4.1.2.  */
+  if (lhs->ts.type == BT_CLASS)
+    {
+      gfc_error ("Variable must not be polymorphic in assignment at %L",
+		 &lhs->where);
+      return false;
+    }
+
   gfc_check_assign (lhs, rhs, 1);
   return false;
 }

[-- Attachment #3: class_5.f03 --]
[-- Type: application/octet-stream, Size: 473 bytes --]

! { dg-do compile }
!
! PR 41719: [OOP] invalid: Intrinsic assignment involving polymorphic variables
!
! Contributed by Tobias Burnus <burnus@gcc.gnu.org>

 implicit none

 type t1
   integer :: a
 end type

 type, extends(t1) :: t2
   integer :: b
 end type

 class(t1),pointer :: cp
 type(t2) :: x

 x = t2(45,478)
 allocate(t2 :: cp)

 cp = x   ! { dg-error "Variable must not be polymorphic" }

 select type (cp)
 type is (t2)
   print *, cp%a, cp%b
 end select

end
 

             reply	other threads:[~2009-10-16 20:46 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-10-16 20:58 Janus Weil [this message]
2009-10-16 20:58 ` Tobias Burnus
2009-10-16 21: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=854832d40910161346g62f3a412k2fe7c71d5b7461f5@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).