Bug 47572 - [OOP] Invalid: Allocatable polymorphic with init expression.
Summary: [OOP] Invalid: Allocatable polymorphic with init expression.
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.6.0
: P3 normal
Target Milestone: ---
Assignee: janus
URL:
Keywords: accepts-invalid
Depends on:
Blocks:
 
Reported: 2011-02-01 14:33 UTC by Tobias Burnus
Modified: 2011-02-02 13:12 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2011-02-01 15:52:21


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2011-02-01 14:33:44 UTC
Found at http://groups.google.com/group/comp.lang.fortran/browse_thread/thread/763785b16883ed68

The program looks very odd and surely is wrong; however, gfortran accepts it.

ifort does:
  error #6562: A data initialization-expr is not valid for this object.  [B]

I assume that one checks against the CLASS container and not against the actual _data object.

"C506 (R503) An initialization shall not appear if object-name is a dummy argument, a function result, an object in a named common block unless the type declaration is in a block data program unit, an object in blank common, an allocatable variable, or an automatic object." (F2008)



program scalarallocation
    type test
        real :: a
    end type
    class (test), allocatable :: b = test(3.4)
    print *,'B', allocated(b)
end program
Comment 1 janus 2011-02-01 15:52:21 UTC
The following should be enough to fix it:

Index: gcc/fortran/resolve.c
===================================================================
--- gcc/fortran/resolve.c       (revision 169479)
+++ gcc/fortran/resolve.c       (working copy)
@@ -10063,7 +10063,8 @@ resolve_fl_variable (gfc_symbol *sym, int mp_flag)
   /* Reject illegal initializers.  */
   if (!sym->mark && sym->value)
     {
-      if (sym->attr.allocatable)
+      if (sym->attr.allocatable || (sym->ts.type == BT_CLASS
+                                   && CLASS_DATA (sym)->attr.allocatable))
        gfc_error ("Allocatable '%s' at %L cannot have an initializer",
                   sym->name, &sym->declared_at);
       else if (sym->attr.external)
Comment 2 janus 2011-02-02 13:11:54 UTC
Author: janus
Date: Wed Feb  2 13:11:50 2011
New Revision: 169520

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=169520
Log:
2011-02-02  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/47572
	* resolve.c (resolve_fl_variable): Handle polymorphic allocatables.


2011-02-02  Janus Weil  <janus@gcc.gnu.org>

	PR fortran/47572
	* gfortran.dg/class_36.f03: New.

Added:
    trunk/gcc/testsuite/gfortran.dg/class_36.f03
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/resolve.c
    trunk/gcc/testsuite/ChangeLog
Comment 3 janus 2011-02-02 13:12:56 UTC
Fixed with r169520. Closing.