public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/34402]  New: Diagnose illegal initialization of derived type containing allocatable component
@ 2007-12-09  6:35 w6ws at earthlink dot net
  2007-12-09 13:08 ` [Bug fortran/34402] " burnus at gcc dot gnu dot org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: w6ws at earthlink dot net @ 2007-12-09  6:35 UTC (permalink / raw)
  To: gcc-bugs

The initialization in following test case should be diagnosed as an error:

$ cat nocomp7.f90
module nocomp7
  implicit none

  type bad_t
    real, allocatable :: x(:)
  end type

! The following is illegal!

  type (bad_t) :: bad = bad_t ( (/ 1., 3., 5., 7., 9. /) )

end module
$
$ gfortran --version
GNU Fortran (GCC) 4.3.0 20071005 (experimental) [trunk revision 127783]
Copyright (C) 2007 Free Software Foundation, Inc.

GNU Fortran comes with NO WARRANTY, to the extent permitted by law.
You may redistribute copies of GNU Fortran
under the terms of the GNU General Public License.
For more information about these matters, see the file named COPYING


$
$ gfortran --pedantic -c nocomp7.f90
$


-- 
           Summary: Diagnose illegal initialization of derived type
                    containing allocatable component
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: w6ws at earthlink dot net


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34402


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug fortran/34402] Diagnose illegal initialization of derived type containing allocatable component
  2007-12-09  6:35 [Bug fortran/34402] New: Diagnose illegal initialization of derived type containing allocatable component w6ws at earthlink dot net
@ 2007-12-09 13:08 ` burnus at gcc dot gnu dot org
  2009-12-08 20:33 ` dfranke at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: burnus at gcc dot gnu dot org @ 2007-12-09 13:08 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from burnus at gcc dot gnu dot org  2007-12-09 13:07 -------
NAG f95:
Error: adf.f90, line 10: Initialisation expression for BAD is not constant

ifort:
fortcom: Error: adf.f90, line 10: A data initialization-expr is not valid for
this object.   [BAD]
  type (bad_t) :: bad = bad_t ( (/ 1., 3., 5., 7., 9. /) )
------------------^


-- 

burnus at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
           Keywords|                            |accepts-invalid
   Last reconfirmed|0000-00-00 00:00:00         |2007-12-09 13:07:58
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34402


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug fortran/34402] Diagnose illegal initialization of derived type containing allocatable component
  2007-12-09  6:35 [Bug fortran/34402] New: Diagnose illegal initialization of derived type containing allocatable component w6ws at earthlink dot net
  2007-12-09 13:08 ` [Bug fortran/34402] " burnus at gcc dot gnu dot org
@ 2009-12-08 20:33 ` dfranke at gcc dot gnu dot org
  2009-12-08 21:34 ` w6ws at earthlink dot net
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: dfranke at gcc dot gnu dot org @ 2009-12-08 20:33 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from dfranke at gcc dot gnu dot org  2009-12-08 20:33 -------
(In reply to comment #0)
> ! The following is illegal!
>   type (bad_t) :: bad = bad_t ( (/ 1., 3., 5., 7., 9. /) )

I don't get it. "Fortran 95/2003 explained" by Metcalf has exactly this in the
example (figure 12.3, p243) for allocatable components. I don't have the
standard section, but Metcalf states:
"In a structure constructor, an expression corresponding to an allocatable
component must be an array or a reference to the intrinsic function NULL with
no arguments. [...] If it is an array, but not an allocatable array, the
component is allocated with the same bounds and is assigned the same value."

If compiled with "-std=f95", gfortran complains about allocatable components in
general and accepts it with "-std=f2003". So, where's the actual problem?


-- 

dfranke at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dfranke at gcc dot gnu dot
                   |                            |org
             Status|NEW                         |WAITING


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34402


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug fortran/34402] Diagnose illegal initialization of derived type containing allocatable component
  2007-12-09  6:35 [Bug fortran/34402] New: Diagnose illegal initialization of derived type containing allocatable component w6ws at earthlink dot net
  2007-12-09 13:08 ` [Bug fortran/34402] " burnus at gcc dot gnu dot org
  2009-12-08 20:33 ` dfranke at gcc dot gnu dot org
@ 2009-12-08 21:34 ` w6ws at earthlink dot net
  2009-12-08 21:42 ` dfranke at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: w6ws at earthlink dot net @ 2009-12-08 21:34 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from w6ws at earthlink dot net  2009-12-08 21:34 -------
(In reply to comment #2)
> I don't get it. "Fortran 95/2003 explained" by Metcalf has exactly this in the
> example (figure 12.3, p243) for allocatable components... So, where's the actual problem?

The example on p243 correctly shows the use of a structure constructor in an
assignment statement.  This bug report is different in that it concerns a
structure constructor in the initializer portion of a TYPE statement (where the
derived type contains an ALLOCATABLE.)


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34402


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug fortran/34402] Diagnose illegal initialization of derived type containing allocatable component
  2007-12-09  6:35 [Bug fortran/34402] New: Diagnose illegal initialization of derived type containing allocatable component w6ws at earthlink dot net
                   ` (2 preceding siblings ...)
  2009-12-08 21:34 ` w6ws at earthlink dot net
@ 2009-12-08 21:42 ` dfranke at gcc dot gnu dot org
  2009-12-09  0:28 ` w6ws at earthlink dot net
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: dfranke at gcc dot gnu dot org @ 2009-12-08 21:42 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from dfranke at gcc dot gnu dot org  2009-12-08 21:41 -------
(In reply to comment #3)
> (In reply to comment #2)
> > I don't get it. "Fortran 95/2003 explained" by Metcalf has exactly this in the
> > example (figure 12.3, p243) for allocatable components... So, where's the actual problem?
> 
> The example on p243 correctly shows the use of a structure constructor in an
> assignment statement.  This bug report is different in that it concerns a
> structure constructor in the initializer portion of a TYPE statement (where 
> the derived type contains an ALLOCATABLE.)

And while writing the above, I didn't take this as significant difference.
However, it dawns on me that the crucial point is, that variables with
initializer get the SAVE attribute which doesn't go well with the ALLOCATABLE
components. Correct?


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34402


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug fortran/34402] Diagnose illegal initialization of derived type containing allocatable component
  2007-12-09  6:35 [Bug fortran/34402] New: Diagnose illegal initialization of derived type containing allocatable component w6ws at earthlink dot net
                   ` (3 preceding siblings ...)
  2009-12-08 21:42 ` dfranke at gcc dot gnu dot org
@ 2009-12-09  0:28 ` w6ws at earthlink dot net
  2009-12-09 22:05 ` dfranke at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: w6ws at earthlink dot net @ 2009-12-09  0:28 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from w6ws at earthlink dot net  2009-12-09 00:27 -------
(In reply to comment #4)
> ... it dawns on me that the crucial point is, that variables with
> initializer get the SAVE attribute which doesn't go well with the ALLOCATABLE
> components. Correct?

I am not sure why they put the restriction in.  But note that one *can* use
null() in a structure constructor for the allocatable component.  So the
following is legal:

  type xyzzy
    integer, allocatable :: x(:)
    real :: y
  end type

  type(xyzzy) :: plugh = xyzzy (null (), 123.456)

See 7.1.7(3) in F2003 (and 7.1.12(3) in the F2008 draft.)


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34402


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug fortran/34402] Diagnose illegal initialization of derived type containing allocatable component
  2007-12-09  6:35 [Bug fortran/34402] New: Diagnose illegal initialization of derived type containing allocatable component w6ws at earthlink dot net
                   ` (4 preceding siblings ...)
  2009-12-09  0:28 ` w6ws at earthlink dot net
@ 2009-12-09 22:05 ` dfranke at gcc dot gnu dot org
  2009-12-10 19:57 ` dfranke at gcc dot gnu dot org
  2009-12-10 19:59 ` dfranke at gcc dot gnu dot org
  7 siblings, 0 replies; 9+ messages in thread
From: dfranke at gcc dot gnu dot org @ 2009-12-09 22:05 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from dfranke at gcc dot gnu dot org  2009-12-09 22:05 -------
(In reply to comment #5)
> See 7.1.7(3) in F2003 (and 7.1.12(3) in the F2008 draft.)

Walter, thanks for reference!


-- 

dfranke at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |dfranke at gcc dot gnu dot
                   |dot org                     |org
             Status|WAITING                     |ASSIGNED
   Last reconfirmed|2007-12-09 13:07:58         |2009-12-09 22:05:38
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34402


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug fortran/34402] Diagnose illegal initialization of derived type containing allocatable component
  2007-12-09  6:35 [Bug fortran/34402] New: Diagnose illegal initialization of derived type containing allocatable component w6ws at earthlink dot net
                   ` (5 preceding siblings ...)
  2009-12-09 22:05 ` dfranke at gcc dot gnu dot org
@ 2009-12-10 19:57 ` dfranke at gcc dot gnu dot org
  2009-12-10 19:59 ` dfranke at gcc dot gnu dot org
  7 siblings, 0 replies; 9+ messages in thread
From: dfranke at gcc dot gnu dot org @ 2009-12-10 19:57 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from dfranke at gcc dot gnu dot org  2009-12-10 19:57 -------
Subject: Bug 34402

Author: dfranke
Date: Thu Dec 10 19:57:16 2009
New Revision: 155138

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=155138
Log:
gcc/fortran/:
2009-12-10  Daniel Franke  <franke.daniel@gmail.com>

        PR fortran/34402
        * expr.c (check_alloc_comp_init): New.
        (check_init_expr): Verify that allocatable components
        are not data-initalized.

gcc/testsuite/:
2009-12-10  Daniel Franke  <franke.daniel@gmail.com>

        PR fortran/34402
        * gfortran.dg/alloc_comp_init_expr.f03: New.


Added:
    trunk/gcc/testsuite/gfortran.dg/alloc_comp_init_expr.f03
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/expr.c
    trunk/gcc/testsuite/ChangeLog


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34402


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug fortran/34402] Diagnose illegal initialization of derived type containing allocatable component
  2007-12-09  6:35 [Bug fortran/34402] New: Diagnose illegal initialization of derived type containing allocatable component w6ws at earthlink dot net
                   ` (6 preceding siblings ...)
  2009-12-10 19:57 ` dfranke at gcc dot gnu dot org
@ 2009-12-10 19:59 ` dfranke at gcc dot gnu dot org
  7 siblings, 0 replies; 9+ messages in thread
From: dfranke at gcc dot gnu dot org @ 2009-12-10 19:59 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from dfranke at gcc dot gnu dot org  2009-12-10 19:59 -------
Fixed in trunk. Closing.


-- 

dfranke at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED
   Target Milestone|---                         |4.5.0


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34402


^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2009-12-10 19:59 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-12-09  6:35 [Bug fortran/34402] New: Diagnose illegal initialization of derived type containing allocatable component w6ws at earthlink dot net
2007-12-09 13:08 ` [Bug fortran/34402] " burnus at gcc dot gnu dot org
2009-12-08 20:33 ` dfranke at gcc dot gnu dot org
2009-12-08 21:34 ` w6ws at earthlink dot net
2009-12-08 21:42 ` dfranke at gcc dot gnu dot org
2009-12-09  0:28 ` w6ws at earthlink dot net
2009-12-09 22:05 ` dfranke at gcc dot gnu dot org
2009-12-10 19:57 ` dfranke at gcc dot gnu dot org
2009-12-10 19:59 ` dfranke at gcc dot gnu dot org

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).