public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/45337] gfortran accepts pointer initialization of DT dummy arguments w/ INTENT(OUT)
       [not found] <bug-45337-4@http.gcc.gnu.org/bugzilla/>
@ 2013-03-29  9:27 ` Joost.VandeVondele at mat dot ethz.ch
  2020-07-07 13:50 ` markeggleston at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 11+ messages in thread
From: Joost.VandeVondele at mat dot ethz.ch @ 2013-03-29  9:27 UTC (permalink / raw)
  To: gcc-bugs


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

Joost VandeVondele <Joost.VandeVondele at mat dot ethz.ch> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|2010-08-19 09:47:08         |2013-03-29
                 CC|                            |Joost.VandeVondele at mat
                   |                            |dot ethz.ch

--- Comment #12 from Joost VandeVondele <Joost.VandeVondele at mat dot ethz.ch> 2013-03-29 09:27:23 UTC ---
comment #11 still fails on 4.9 trunk.


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

* [Bug fortran/45337] gfortran accepts pointer initialization of DT dummy arguments w/ INTENT(OUT)
       [not found] <bug-45337-4@http.gcc.gnu.org/bugzilla/>
  2013-03-29  9:27 ` [Bug fortran/45337] gfortran accepts pointer initialization of DT dummy arguments w/ INTENT(OUT) Joost.VandeVondele at mat dot ethz.ch
@ 2020-07-07 13:50 ` markeggleston at gcc dot gnu.org
  2020-07-13 15:38 ` cvs-commit at gcc dot gnu.org
  2020-07-14  7:05 ` markeggleston at gcc dot gnu.org
  3 siblings, 0 replies; 11+ messages in thread
From: markeggleston at gcc dot gnu.org @ 2020-07-07 13:50 UTC (permalink / raw)
  To: gcc-bugs

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

markeggleston at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |markeggleston at gcc dot gnu.org

--- Comment #13 from markeggleston at gcc dot gnu.org ---
Regarding patch in comment 7 and test case in comment 11.

It seems to me that it is only necessary to to check for the dummy attribute:

diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c
index 223dcccce91..730d11105bd 100644
--- a/gcc/fortran/resolve.c
+++ b/gcc/fortran/resolve.c
@@ -12918,8 +12918,7 @@ resolve_fl_variable (gfc_symbol *sym, int mp_flag)
       else if (sym->attr.external)
        gfc_error ("External %qs 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))
+      else if (sym->attr.dummy)
        gfc_error ("Dummy %qs at %L cannot have an initializer",
                   sym->name, &sym->declared_at);
       else if (sym->attr.intrinsic)


For the test case from comment 1:

pr45337_1.f90:3:20:

    3 | subroutine lengthX(x, i)
      |                    1
Error: Dummy 'x' at (1) cannot have an initializer
pr45337_1.f90:14:7:

   14 |   use ptrmod
      |       1
Fatal Error: Cannot open module file 'ptrmod.mod' for reading at (1): No such
file or directory
compilation terminated.


and for the test case from comment 11:

pr45337_2.f90:7:16:

    7 |   subroutine x(a, b, c)
      |                1
Error: Dummy 'a' at (1) cannot have an initializer
pr45337_2.f90:7:19:

    7 |   subroutine x(a, b, c)
      |                   1
Error: Dummy 'b' at (1) cannot have an initializer


Regarding comments 8, 9 and 10.  I think the the error messages are sufficient
as is.

No additional test failures encountered when running make check-fortran.

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

* [Bug fortran/45337] gfortran accepts pointer initialization of DT dummy arguments w/ INTENT(OUT)
       [not found] <bug-45337-4@http.gcc.gnu.org/bugzilla/>
  2013-03-29  9:27 ` [Bug fortran/45337] gfortran accepts pointer initialization of DT dummy arguments w/ INTENT(OUT) Joost.VandeVondele at mat dot ethz.ch
  2020-07-07 13:50 ` markeggleston at gcc dot gnu.org
@ 2020-07-13 15:38 ` cvs-commit at gcc dot gnu.org
  2020-07-14  7:05 ` markeggleston at gcc dot gnu.org
  3 siblings, 0 replies; 11+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-07-13 15:38 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #14 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Mark Eggleston
<markeggleston@gcc.gnu.org>:

https://gcc.gnu.org/g:bae66e0f04323ba9d5daf60fcb997de925100e3e

commit r11-2065-gbae66e0f04323ba9d5daf60fcb997de925100e3e
Author: Mark Eggleston <markeggleston@gcc.gnu.org>
Date:   Wed Jun 10 07:22:50 2020 +0100

    Fortran  : accepts pointer initialization of DT dummy args PR45337

    Initialisation of a variable results in an implicit save attribute
    being added to the variable.  The save attribute is not allowed for
    variables with the dummy attribute set.  Initialisation should be
    rejected for dummy variables.

    2020-07-13  Mark Eggleston  <markeggleston@gcc.gnu.org>

    gcc/fortran/

            PR fortran/45337
            * resolve.c (resolve_fl_variable): Remove type and intent
            checks from the check for dummy.

    2020-07-13  Mark Eggleston  <markeggleston@gcc.gnu.org>

    gcc/testsuite/

            PR fortran/45337
            * gfortran.dg/pr45337_1.f90: New test.
            * gfortran.dg/pr45337_2.f90: New test.

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

* [Bug fortran/45337] gfortran accepts pointer initialization of DT dummy arguments w/ INTENT(OUT)
       [not found] <bug-45337-4@http.gcc.gnu.org/bugzilla/>
                   ` (2 preceding siblings ...)
  2020-07-13 15:38 ` cvs-commit at gcc dot gnu.org
@ 2020-07-14  7:05 ` markeggleston at gcc dot gnu.org
  3 siblings, 0 replies; 11+ messages in thread
From: markeggleston at gcc dot gnu.org @ 2020-07-14  7:05 UTC (permalink / raw)
  To: gcc-bugs

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

markeggleston at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
             Status|NEW                         |RESOLVED

--- Comment #15 from markeggleston at gcc dot gnu.org ---
Committed to master.

^ permalink raw reply	[flat|nested] 11+ 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-20  8:57 ` jv244 at cam dot ac dot uk
@ 2010-08-20 22:29 ` burnus at gcc dot gnu dot org
  6 siblings, 0 replies; 11+ 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] 11+ 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-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
  6 siblings, 0 replies; 11+ 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] 11+ 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-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
  6 siblings, 0 replies; 11+ 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] 11+ 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
                   ` (2 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)
  6 siblings, 0 replies; 11+ 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] 11+ 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
  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
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 11+ 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] 11+ 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
  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)
  6 siblings, 0 replies; 11+ 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] 11+ 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
@ 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)
  6 siblings, 0 replies; 11+ 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] 11+ messages in thread

end of thread, other threads:[~2020-07-14  7:05 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-45337-4@http.gcc.gnu.org/bugzilla/>
2013-03-29  9:27 ` [Bug fortran/45337] gfortran accepts pointer initialization of DT dummy arguments w/ INTENT(OUT) Joost.VandeVondele at mat dot ethz.ch
2020-07-07 13:50 ` markeggleston at gcc dot gnu.org
2020-07-13 15:38 ` cvs-commit at gcc dot gnu.org
2020-07-14  7:05 ` markeggleston at gcc dot gnu.org
2010-08-19  9:14 [Bug fortran/45337] New: intent(out) and pointer => null() 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).