Bug 38065

Summary: private/public confusion with a contained function
Product: gcc Reporter: Norman S. Clerman <norm.clerman>
Component: fortranAssignee: Tobias Burnus <burnus>
Status: RESOLVED FIXED    
Severity: normal CC: burnus, gcc-bugs
Priority: P3 Keywords: rejects-valid
Version: 4.4.0   
Target Milestone: ---   
Host: Target:
Build: Known to work:
Known to fail: 4.4.0 Last reconfirmed: 2008-11-11 14:35:00
Bug Depends on:    
Bug Blocks: 32834    
Attachments: bug5.tgz
bug5a.tgz

Description Norman S. Clerman 2008-11-09 14:52:01 UTC
Hello,

Thank you for fixing the last bug I reported, number 37445.

I am attempting to build my lens design program. I encounter the following
errors when I compile file geomotfM.f90:

/home/norm/design/source/geomotfM.f90:836.4:

    function CreateLine ( RayData, MaxFreq, NoOfGoodRays, ChromaticWeights, Err
   1
Error: PUBLIC function 'createline' at (1) cannot be of PRIVATE type 'tline'

This is incorrect. Both the type TLine and the function CreateLine are private to the module. The NAG, Intel and g95 compilers all compile this.

I tried to reproduce this problem with a small example, but I did not succeed. 

As soon as I am assigned a bug number, I will upload a tar file, bug5.tgz to
the following address: gcc-bugzilla@gcc.gnu.org. Unpack the file and invoke the
shell script bug5.sh to reproduce the problem.

I'll indicate the bug number in the subject line.

I am running Open SuSE 10.1 on a dual core Athlon chip. I'm using the gcc-trunk
build:

norm@oxford:~/design/gfortran/production> gfortran --version
GNU Fortran (GCC) 4.4.0 20081109 (experimental) [trunk revision 141714]
Copyright (C) 2008 Free Software Foundation, Inc.

Thank you for your attention.

Norm Clerman
Comment 1 Norman S. Clerman 2008-11-09 14:57:04 UTC
Subject: bug 38065 (my bug5)

Attached is the file you will need to reproduce the problem.

Thanks again for your assistance.

Norm Clerman
Comment 2 Norman S. Clerman 2008-11-09 14:57:04 UTC
Created attachment 16640 [details]
bug5.tgz
Comment 3 Joost VandeVondele 2008-11-09 17:22:34 UTC
(In reply to comment #2)
> Created an attachment (id=16640) [edit]
> 

the shell script seems to have a few lines referring to your home, but it looks like most files are there. 

One missing file is:

 treetypeT.f90

please check that all files needed to reproduce the error are in the tarball, and that the procedure how to reproduce the error is clear enough. 
Comment 4 Norman S. Clerman 2008-11-09 21:54:10 UTC
Subject: Re:  bug5

Thank you for your prompt reply. I have reassembled all the files to reproduce the problem and they are in the attached file bug5a.tgz.

My apologies for any problem this has caused.

Norm Clerman

---- jv244 at cam dot ac dot uk <gcc-bugzilla@gcc.gnu.org> wrote: 
> 
> 
> ------- Comment #3 from jv244 at cam dot ac dot uk  2008-11-09 17:22 -------
> (In reply to comment #2)
> > Created an attachment (id=16640)
>  --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=16640&action=view) [edit]
> > 
> 
> the shell script seems to have a few lines referring to your home, but it looks
> like most files are there. 
> 
> One missing file is:
> 
>  treetypeT.f90
> 
> please check that all files needed to reproduce the error are in the tarball,
> and that the procedure how to reproduce the error is clear enough. 
> 
> 
> -- 
> 
> 
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38065
> 
> ------- You are receiving this mail because: -------
> You reported the bug, or are watching the reporter.
Comment 5 Norman S. Clerman 2008-11-09 21:54:10 UTC
Created attachment 16642 [details]
bug5a.tgz
Comment 6 Joost VandeVondele 2008-11-11 13:28:28 UTC
reduced:

MODULE M1
  IMPLICIT NONE
  PRIVATE
  TYPE T1
   INTEGER :: I1
  END TYPE T1
  PUBLIC :: S1
CONTAINS
  SUBROUTINE S1
  CONTAINS
   TYPE(T1) FUNCTION F1()
   END FUNCTION F1
  END SUBROUTINE S1
END MODULE M1
Comment 7 Norman S. Clerman 2008-11-11 13:46:13 UTC
Subject: Re:  private/public confusion with a contained
 function

Hello,

  As best I can see, your reduction of the problem is not correct; in it subroutine S1 should be private, not public.

Yours truly,

Norm Clerman

---- jv244 at cam dot ac dot uk <gcc-bugzilla@gcc.gnu.org> wrote: 
> 
> 
> ------- Comment #6 from jv244 at cam dot ac dot uk  2008-11-11 13:28 -------
> reduced:
> 
> MODULE M1
>   IMPLICIT NONE
>   PRIVATE
>   TYPE T1
>    INTEGER :: I1
>   END TYPE T1
>   PUBLIC :: S1
> CONTAINS
>   SUBROUTINE S1
>   CONTAINS
>    TYPE(T1) FUNCTION F1()
>    END FUNCTION F1
>   END SUBROUTINE S1
> END MODULE M1
> 
> 
> -- 
> 
> jv244 at cam dot ac dot uk changed:
> 
>            What    |Removed                     |Added
> ----------------------------------------------------------------------------
> OtherBugsDependingO|                            |32834
>               nThis|                            |
>              Status|UNCONFIRMED                 |NEW
>      Ever Confirmed|0                           |1
>            Keywords|                            |rejects-valid
>       Known to fail|                            |4.4.0
>    Last reconfirmed|0000-00-00 00:00:00         |2008-11-11 13:28:28
>                date|                            |
>             Summary|bug5                        |private/public confusion
>                    |                            |with a contained function
> 
> 
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38065
> 
> ------- You are receiving this mail because: -------
> You reported the bug, or are watching the reporter.

Comment 8 Joost VandeVondele 2008-11-11 14:14:41 UTC
(In reply to comment #7)
>   As best I can see, your reduction of the problem is not correct; in it
> subroutine S1 should be private, not public.

I don't think so. See your code, S1 ~ GeomMTF, which is public. The problem is the contained function F1 (your CreateLine), which incorrectly gets a 'public' attribute. Note that the same, incorrect error message is displayed for this testcase.
Comment 9 Tobias Burnus 2008-11-11 14:28:46 UTC
(In reply to comment #6)
> reduced:
>
>   SUBROUTINE S1
>   CONTAINS
>    TYPE(T1) FUNCTION F1()
>    END FUNCTION F1
>   END SUBROUTINE S1

Error: PUBLIC function 'f1' at (1) cannot be of PRIVATE type 't1'

gfortran has two bugs:
a) F1 is an internal function and thus PUBLIC/PRIVATE does not apply
b) If one makes F1 a (PUBLIC) *module* function, the program still would be a valid Fortran 2003 program (and an invalid Fortran 95 program).

I still need to test whether the original program is fixed or not; there are quite a lot files ... 

Fix:
+++ gcc/fortran/resolve.c       (Arbeitskopie)
@@ -10181,0 +10182 @@ resolve_fntype (gfc_namespace *ns)
+      && !sym->attr.contained
@@ -10186,2 +10187,3 @@ resolve_fntype (gfc_namespace *ns)
-      gfc_error ("PUBLIC function '%s' at %L cannot be of PRIVATE type '%s'",
-                sym->name, &sym->declared_at, sym->ts.derived->name);
+      gfc_notify_std (GFC_STD_F2003, "Fortran 2003: PUBLIC function '%s' at "
+                     "%L of PRIVATE type '%s'", sym->name,
+                     &sym->declared_at, sym->ts.derived->name);
Comment 10 Tobias Burnus 2008-11-11 14:35:00 UTC
bug5a.tgz compiled successfully with the patch in comment 9.
Comment 11 Norman S. Clerman 2008-11-11 14:35:59 UTC
Subject: Re:  private/public confusion with a contained
 function

Hello,

  Thank you for responding so promptly.

  Yes, I see what's going on now. It wasn't apparent to me that my function CreateLine was incorrectly acquiring the ''public' attribute. This explains why I could not reduce the problem as you have.

Norm Clerman

---- jv244 at cam dot ac dot uk <gcc-bugzilla@gcc.gnu.org> wrote: 
> 
> 
> ------- Comment #8 from jv244 at cam dot ac dot uk  2008-11-11 14:14 -------
> (In reply to comment #7)
> >   As best I can see, your reduction of the problem is not correct; in it
> > subroutine S1 should be private, not public.
> 
> I don't think so. See your code, S1 ~ GeomMTF, which is public. The problem is
> the contained function F1 (your CreateLine), which incorrectly gets a 'public'
> attribute. Note that the same, incorrect error message is displayed for this
> testcase.
> 
> 
> -- 
> 
> 
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38065
> 
> ------- You are receiving this mail because: -------
> You reported the bug, or are watching the reporter.

Comment 12 Tobias Burnus 2008-11-12 07:00:57 UTC
Subject: Bug 38065

Author: burnus
Date: Wed Nov 12 06:59:33 2008
New Revision: 141780

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=141780
Log:
2008-11-12  Tobias Burnus  <burnus@net-b.de>

        PR fortran/38065
        * resolve.c (resolve_fntype): Fix private derived type checking.

2008-11-12  Tobias Burnus  <burnus@net-b.de>

        PR fortran/38065
        * gfortran.dg/private_type_11.f90: New test.
        * gfortran.dg/private_type_12.f90: New test.


Added:
    trunk/gcc/testsuite/gfortran.dg/private_type_11.f90
    trunk/gcc/testsuite/gfortran.dg/private_type_12.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/resolve.c
    trunk/gcc/testsuite/ChangeLog

Comment 13 Tobias Burnus 2008-11-12 07:02:50 UTC
FIXED on the trunk (4.4.0).
Comment 14 Tobias Burnus 2008-11-12 18:39:39 UTC
Subject: Bug 38065

Author: burnus
Date: Wed Nov 12 18:38:08 2008
New Revision: 141798

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=141798
Log:
2008-11-12  Tobias Burnus  <burnus@net-b.de>

       PR fortran/38065
       PR fortran/38094
       * gfortran.dg/private_type_4.f90: Add -std=f95 option.


Modified:
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/private_type_4.f90