public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/45337]  New: intent(out) and pointer => null()
@ 2010-08-19  9:14 linuxl4 at sohu dot com
  2010-08-19  9:14 ` [Bug fortran/45337] " linuxl4 at sohu dot com
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: linuxl4 at sohu dot com @ 2010-08-19  9:14 UTC (permalink / raw)
  To: gcc-bugs

$ gfortran --version
GNU Fortran (GCC) 4.5.2 20100819 (prerelease)

which is wrong? and WHY?


-- 
           Summary: intent(out) and pointer => null()
           Product: gcc
           Version: 4.5.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: linuxl4 at sohu dot com
 GCC build triplet: x86_64 - redhat - linux
  GCC host triplet: x86_64 - redhat - linux
GCC target triplet: x86_64 - redhat - linux


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


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

* [Bug fortran/45337] intent(out) and pointer => null()
  2010-08-19  9:14 [Bug fortran/45337] New: intent(out) and pointer => null() linuxl4 at sohu dot com
@ 2010-08-19  9:14 ` linuxl4 at sohu dot com
  2010-08-19  9:22 ` jv244 at cam dot ac dot uk
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: linuxl4 at sohu dot com @ 2010-08-19  9:14 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from linuxl4 at sohu dot com  2010-08-19 09:14 -------
module ptrmod
contains
subroutine lengthX(x, i)
   implicit none
   real, pointer, intent(out) :: x(:)=>null()
   integer :: i
   allocate(x(i))
   x=i
end subroutine
end module

program main
  use ptrmod
  implicit none
  real, pointer :: x(:)
  integer :: i
  do i=1,5
     call lengthX(x, i)
     print *, size(x), x
  enddo
  if(associated(x)) deallocate(x)
  x=>null()
end program


-- 


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


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

* [Bug fortran/45337] intent(out) and pointer => null()
  2010-08-19  9:14 [Bug fortran/45337] New: intent(out) and pointer => null() linuxl4 at sohu dot com
  2010-08-19  9:14 ` [Bug fortran/45337] " linuxl4 at sohu dot com
  2010-08-19  9:22 ` jv244 at cam dot ac dot uk
@ 2010-08-19  9:22 ` linuxl4 at sohu dot com
  2010-08-19  9:26 ` linuxl4 at sohu dot com
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: linuxl4 at sohu dot com @ 2010-08-19  9:22 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from linuxl4 at sohu dot com  2010-08-19 09:22 -------
module ptrmod
  implicit none
  type inde
     real :: x
  end type   

contains
subroutine lengthY(indexx)
   implicit none
   type(inde), pointer, intent(out) :: indexx(:)=>null()
end subroutine
end module

program main
  use ptrmod
  implicit none
  type(inde), pointer :: indexx(:)=>null()
  call lengthY(indexx)
end program


-- 


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


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

* [Bug fortran/45337] intent(out) and pointer => null()
  2010-08-19  9:14 [Bug fortran/45337] New: intent(out) and pointer => null() linuxl4 at sohu dot com
  2010-08-19  9:14 ` [Bug fortran/45337] " linuxl4 at sohu dot com
@ 2010-08-19  9:22 ` jv244 at cam dot ac dot uk
  2010-08-19  9:22 ` linuxl4 at sohu dot com
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: jv244 at cam dot ac dot uk @ 2010-08-19  9:22 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from jv244 at cam dot ac dot uk  2010-08-19 09:22 -------
(In reply to comment #1)
> module ptrmod
> contains
> subroutine lengthX(x, i)
>    implicit none
>    real, pointer, intent(out) :: x(:)=>null()

you can't initialize a dummy argument, since initialization implies save. Just
put 'NULLIFY(x)' in the body of the subroutine. Intents for pointers is fine,
but not Fortran95 (2003/2008?)

>    integer :: i
>    allocate(x(i))
>    x=i
> end subroutine
> end module
> 
> program main
>   use ptrmod
>   implicit none
>   real, pointer :: x(:)
>   integer :: i
>   do i=1,5
>      call lengthX(x, i)
>      print *, size(x), x
>   enddo
>   if(associated(x)) deallocate(x)
>   x=>null()
> end program
> 


-- 

jv244 at cam dot ac dot uk changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


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


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

* [Bug fortran/45337] intent(out) and pointer => null()
  2010-08-19  9:14 [Bug fortran/45337] New: intent(out) and pointer => null() linuxl4 at sohu dot com
                   ` (2 preceding siblings ...)
  2010-08-19  9:22 ` linuxl4 at sohu dot com
@ 2010-08-19  9:26 ` linuxl4 at sohu dot com
  2010-08-19  9:40 ` [Bug fortran/45337] gfortran accepts pointer initialization of DT dummy arguments w/ INTENT(OUT) burnus at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: linuxl4 at sohu dot com @ 2010-08-19  9:26 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from linuxl4 at sohu dot com  2010-08-19 09:26 -------
Too fast your answer interrupt My question. 


-- 


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


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

* [Bug fortran/45337] gfortran accepts pointer initialization of DT dummy arguments w/ INTENT(OUT)
  2010-08-19  9:14 [Bug fortran/45337] New: intent(out) and pointer => null() linuxl4 at sohu dot com
                   ` (3 preceding siblings ...)
  2010-08-19  9:26 ` linuxl4 at sohu dot com
@ 2010-08-19  9:40 ` burnus at gcc dot gnu dot org
  2010-08-19  9:47 ` burnus at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: burnus at gcc dot gnu dot org @ 2010-08-19  9:40 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from burnus at gcc dot gnu dot org  2010-08-19 09:40 -------
(In reply to comment #2)
> Intents for pointers is fine, but not Fortran95 (2003/2008?)

Intents for pointers is Fortran 2003; it applies to the pointer association
status and not to the value.


The programs in comment 0 and comment 2 are both invalid.

  type(inde), pointer :: indexx(:)=>null()

means that "indexx" is initialized - which is only possible for variables which
are in static memory ("SAVE"; the assignment implies the SAVE). That's OK for
the line above, but not for dummy arguments to subroutines.

Note: In C  "int a = 5;" and "int a; a = 5;" have the same meaning. In Fortran
not! "integer :: a = 5" means that "a" is in static memory ("SAVE") and will
only be initialized once at program start. Whereas for "integer :: a; a = 5" 
the assignment happens every time the line is subroutine is called.

 * * *

Regarding the accepts invalid bug:

While for the program in comment 0, gfortran prints the error
  Error: Dummy 'x' at (1) cannot have an initializer
it compiles the program in comment 2.

Note: If one removes the INTENT(OUT) or has (as in comment 0) no derived-type
dummy, the error is printed.


-- 

burnus at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |UNCONFIRMED
           Keywords|                            |accepts-invalid
         Resolution|INVALID                     |
            Summary|intent(out) and pointer =>  |gfortran accepts pointer
                   |null()                      |initialization of DT dummy
                   |                            |arguments w/ INTENT(OUT)


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


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

* [Bug fortran/45337] gfortran accepts pointer initialization of DT dummy arguments w/ INTENT(OUT)
  2010-08-19  9:14 [Bug fortran/45337] New: intent(out) and pointer => null() linuxl4 at sohu dot com
                   ` (4 preceding siblings ...)
  2010-08-19  9:40 ` [Bug fortran/45337] gfortran accepts pointer initialization of DT dummy arguments w/ INTENT(OUT) burnus at gcc dot gnu dot org
@ 2010-08-19  9:47 ` burnus at gcc dot gnu dot org
  2010-08-19  9:56 ` burnus at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: burnus at gcc dot gnu dot org @ 2010-08-19  9:47 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from burnus at gcc dot gnu dot org  2010-08-19 09:47 -------
(In reply to comment #5)
  It should read: program in comment 3 (not in comment 2).

To macius bat:
  Thanks for the bug report!

  It helps if you already state (a) the error message and (b) what you expect
in the first
  description.


-- 

burnus at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
  GCC build triplet|x86_64 - redhat - linux     |
   GCC host triplet|x86_64 - redhat - linux     |
 GCC target triplet|x86_64 - redhat - linux     |
   Last reconfirmed|0000-00-00 00:00:00         |2010-08-19 09:47:08
               date|                            |


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


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

* [Bug fortran/45337] gfortran accepts pointer initialization of DT dummy arguments w/ INTENT(OUT)
  2010-08-19  9:14 [Bug fortran/45337] New: intent(out) and pointer => null() linuxl4 at sohu dot com
                   ` (5 preceding siblings ...)
  2010-08-19  9:47 ` burnus at gcc dot gnu dot org
@ 2010-08-19  9:56 ` burnus at gcc dot gnu dot org
  2010-08-20  6:50 ` linuxl4 at sohu dot com
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: burnus at gcc dot gnu dot org @ 2010-08-19  9:56 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from burnus at gcc dot gnu dot org  2010-08-19 09:56 -------
Untested patch:

Index: resolve.c
===================================================================
--- resolve.c   (revision 163368)
+++ resolve.c   (working copy)
@@ -9724,7 +9724,8 @@ resolve_fl_variable (gfc_symbol *sym, in
        gfc_error ("External '%s' at %L cannot have an initializer",
                   sym->name, &sym->declared_at);
       else if (sym->attr.dummy
-       && !(sym->ts.type == BT_DERIVED && sym->attr.intent == INTENT_OUT))
+       && !(sym->ts.type == BT_DERIVED && sym->attr.intent == INTENT_OUT
+            && !sym->attr.pointer))
        gfc_error ("Dummy '%s' at %L cannot have an initializer",
                   sym->name, &sym->declared_at);
       else if (sym->attr.intrinsic)


-- 


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


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

* [Bug fortran/45337] gfortran accepts pointer initialization of DT dummy arguments w/ INTENT(OUT)
  2010-08-19  9:14 [Bug fortran/45337] New: intent(out) and pointer => null() linuxl4 at sohu dot com
                   ` (6 preceding siblings ...)
  2010-08-19  9:56 ` burnus at gcc dot gnu dot org
@ 2010-08-20  6:50 ` linuxl4 at sohu dot com
  2010-08-20  8:45 ` burnus at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: linuxl4 at sohu dot com @ 2010-08-20  6:50 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from linuxl4 at sohu dot com  2010-08-20 06:50 -------
Error: Dummy 'x' at (1) cannot have an initializer

I think this is easy to understand, an additional short message about why it
can't have an initializer will be better.

> 
>   It helps if you already state (a) the error message and (b) what you expect
> in the first
>   description.
> 


-- 


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


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

* [Bug fortran/45337] gfortran accepts pointer initialization of DT dummy arguments w/ INTENT(OUT)
  2010-08-19  9:14 [Bug fortran/45337] New: intent(out) and pointer => null() linuxl4 at sohu dot com
                   ` (7 preceding siblings ...)
  2010-08-20  6:50 ` linuxl4 at sohu dot com
@ 2010-08-20  8:45 ` burnus at gcc dot gnu dot org
  2010-08-20  8:57 ` jv244 at cam dot ac dot uk
  2010-08-20 22:29 ` burnus at gcc dot gnu dot org
  10 siblings, 0 replies; 12+ messages in thread
From: burnus at gcc dot gnu dot org @ 2010-08-20  8:45 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #9 from burnus at gcc dot gnu dot org  2010-08-20 08:45 -------
(In reply to comment #8)
> Error: Dummy 'x' at (1) cannot have an initializer
> 
> I think this is easy to understand, an additional short message about why it
> can't have an initializer will be better.

Do you have a suggestion?


-- 


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


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

* [Bug fortran/45337] gfortran accepts pointer initialization of DT dummy arguments w/ INTENT(OUT)
  2010-08-19  9:14 [Bug fortran/45337] New: intent(out) and pointer => null() linuxl4 at sohu dot com
                   ` (8 preceding siblings ...)
  2010-08-20  8:45 ` burnus at gcc dot gnu dot org
@ 2010-08-20  8:57 ` jv244 at cam dot ac dot uk
  2010-08-20 22:29 ` burnus at gcc dot gnu dot org
  10 siblings, 0 replies; 12+ messages in thread
From: jv244 at cam dot ac dot uk @ 2010-08-20  8:57 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #10 from jv244 at cam dot ac dot uk  2010-08-20 08:57 -------
(In reply to comment #9)
> (In reply to comment #8)
> > Error: Dummy 'x' at (1) cannot have an initializer
>
> Do you have a suggestion?
>
Error: Dummy argument 'x' at (1) cannot have the save attribute which is
implied by initialization.

?? 


-- 


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


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

* [Bug fortran/45337] gfortran accepts pointer initialization of DT dummy arguments w/ INTENT(OUT)
  2010-08-19  9:14 [Bug fortran/45337] New: intent(out) and pointer => null() linuxl4 at sohu dot com
                   ` (9 preceding siblings ...)
  2010-08-20  8:57 ` jv244 at cam dot ac dot uk
@ 2010-08-20 22:29 ` burnus at gcc dot gnu dot org
  10 siblings, 0 replies; 12+ messages in thread
From: burnus at gcc dot gnu dot org @ 2010-08-20 22:29 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #11 from burnus at gcc dot gnu dot org  2010-08-20 22:28 -------
(In reply to comment #7)
> Untested patch:

The patch is not sufficient as the following example shows for which no warning
is printed:

type t
end type t
type t2
  integer :: j = 7
end type t2
contains
  subroutine x(a, b, c)
    type(t) ,intent(OUT) :: a = t() ! Wrong
    type(t2) ,intent(OUT) :: b = t2() ! Wrong
    type(t2) ,intent(OUT) :: c ! OK, default initializer
end subroutine x
end


-- 


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


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

end of thread, other threads:[~2010-08-20 22:29 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-08-19  9:14 [Bug fortran/45337] New: intent(out) and pointer => null() linuxl4 at sohu dot com
2010-08-19  9:14 ` [Bug fortran/45337] " linuxl4 at sohu dot com
2010-08-19  9:22 ` jv244 at cam dot ac dot uk
2010-08-19  9:22 ` linuxl4 at sohu dot com
2010-08-19  9:26 ` linuxl4 at sohu dot com
2010-08-19  9:40 ` [Bug fortran/45337] gfortran accepts pointer initialization of DT dummy arguments w/ INTENT(OUT) burnus at gcc dot gnu dot org
2010-08-19  9:47 ` burnus at gcc dot gnu dot org
2010-08-19  9:56 ` burnus at gcc dot gnu dot org
2010-08-20  6:50 ` linuxl4 at sohu dot com
2010-08-20  8:45 ` burnus at gcc dot gnu dot org
2010-08-20  8:57 ` jv244 at cam dot ac dot uk
2010-08-20 22:29 ` burnus 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).