public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/42545]  New: TBP: Wrongly reject inherite TBP with types with private components
@ 2009-12-29 18:38 burnus at gcc dot gnu dot org
  2010-01-17 22:35 ` [Bug fortran/42545] " janus at gcc dot gnu dot org
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: burnus at gcc dot gnu dot org @ 2009-12-29 18:38 UTC (permalink / raw)
  To: gcc-bugs

Reported by Reinhold Bader.

The error occurs for inherited type-bound procedures where the extending type
has "PRIVATE" for the components and the TBP procedure is accessed using the
syntax
   <type> % <extended type> % <TBP>
The error message is as follows:

mr_shorter.f90:23.14:

  call  obj%tt%set()
              1
Error: All components of 'ttt' are PRIVATE in structure constructor at (1)

The error is wrong for two reasons:
a) There is no structure constructure visible at all
b) This TBP is public as there is no PRIVATE statement below the CONTAINS in
the type declaration.

See "4.5.4 Type-bound procedures" and esp. last two normative paragraphs of
this section. And see "4.5.6.1 Inheritance" (all refs are F2003):

"An extended type has a scalar, nonpointer, nonallocatable, parent component
with the type and type parameters of the parent type. The name of this
component is the parent type name. It has the accessibility of the parent
type."


! -----------------------------------------
module mo
  implicit none
  type :: tt
    private
    integer :: i = 1
  contains
    procedure :: set
  end type
  type, extends(tt) :: ttt
    private ! <<<<<<<
    real :: x = 2.0
  end type
contains
  subroutine set(this)
    class(tt) :: this
    this%i = -1
  end subroutine
end module
program pr
  use mo
  implicit none
  type(ttt) :: obj
  call  obj%tt%set()
end program
! -------------------

Variants to check:

type tt
 ...
contains
  PRIVATE
! (and optionally "set" explicitly marked as public)

-- and/or --

type, extends(tt) :: t
 ...
contains
  PRIVATE


-- 
           Summary: TBP: Wrongly reject inherite TBP with types with private
                    components
           Product: gcc
           Version: 4.5.0
            Status: UNCONFIRMED
          Keywords: rejects-valid
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: burnus at gcc dot gnu dot org


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


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

* [Bug fortran/42545] TBP: Wrongly reject inherite TBP with types with private components
  2009-12-29 18:38 [Bug fortran/42545] New: TBP: Wrongly reject inherite TBP with types with private components burnus at gcc dot gnu dot org
@ 2010-01-17 22:35 ` janus at gcc dot gnu dot org
  2010-01-17 22:42 ` [Bug fortran/42545] type extension: parent component has wrong accessibility janus at gcc dot gnu dot org
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: janus at gcc dot gnu dot org @ 2010-01-17 22:35 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from janus at gcc dot gnu dot org  2010-01-17 22:35 -------
This problem is not specific to TBPs. It also appears for data components of
the parent type, as the following example shows:

module mo
  implicit none
  type :: tt
    integer :: i = 1
  end type
  type, extends(tt) :: ttt
    private ! <<<<<<<
    real :: x = 2.0
  end type
end module
program pr
  use mo
  implicit none
  type(ttt) :: obj
  print *,obj%tt%i
end program


This is incorrectly rejected with:

  print *,obj%tt%i
                1
Error: All components of 'ttt' are PRIVATE in structure constructor at (1)


-- 


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


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

* [Bug fortran/42545] type extension: parent component has wrong accessibility
  2009-12-29 18:38 [Bug fortran/42545] New: TBP: Wrongly reject inherite TBP with types with private components burnus at gcc dot gnu dot org
  2010-01-17 22:35 ` [Bug fortran/42545] " janus at gcc dot gnu dot org
@ 2010-01-17 22:42 ` janus at gcc dot gnu dot org
  2010-01-17 23:35 ` janus at gcc dot gnu dot org
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: janus at gcc dot gnu dot org @ 2010-01-17 22:42 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from janus at gcc dot gnu dot org  2010-01-17 22:42 -------
Another related example. This one is being accepted, although it is invalid.

module mo
  implicit none
  type,private :: tt
    integer :: i = 1
  end type
  type, extends(tt) :: ttt
    real :: x = 2.0
  end type
end module
program pr
  use mo
  implicit none
  type(ttt) :: obj
  print *,obj%tt%i
end program


The problem clearly is the accessibility of the parent component.


-- 

janus at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|TBP: Wrongly reject inherite|type extension: parent
                   |TBP with types with private |component has wrong
                   |components                  |accessibility


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


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

* [Bug fortran/42545] type extension: parent component has wrong accessibility
  2009-12-29 18:38 [Bug fortran/42545] New: TBP: Wrongly reject inherite TBP with types with private components burnus at gcc dot gnu dot org
  2010-01-17 22:35 ` [Bug fortran/42545] " janus at gcc dot gnu dot org
  2010-01-17 22:42 ` [Bug fortran/42545] type extension: parent component has wrong accessibility janus at gcc dot gnu dot org
@ 2010-01-17 23:35 ` janus at gcc dot gnu dot org
  2010-01-17 23:46 ` janus at gcc dot gnu dot org
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: janus at gcc dot gnu dot org @ 2010-01-17 23:35 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from janus at gcc dot gnu dot org  2010-01-17 23:34 -------
Here is a simple patch for setting the parent component accessibility:

Index: gcc/fortran/decl.c
===================================================================
--- gcc/fortran/decl.c  (revision 155994)
+++ gcc/fortran/decl.c  (working copy)
@@ -6931,6 +6931,7 @@ gfc_match_derived_decl (void)
       p->ts.type = BT_DERIVED;
       p->ts.u.derived = extended;
       p->initializer = gfc_default_initializer (&p->ts);
+      p->attr.access = extended->attr.access;

       /* Set extension level.  */
       if (extended->attr.extension == 255)

This is probably not enough, since the access. specification of the parent type
may come after the daughter type definition. But this already fixes the exmple
in comment #2.


-- 


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


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

* [Bug fortran/42545] type extension: parent component has wrong accessibility
  2009-12-29 18:38 [Bug fortran/42545] New: TBP: Wrongly reject inherite TBP with types with private components burnus at gcc dot gnu dot org
                   ` (2 preceding siblings ...)
  2010-01-17 23:35 ` janus at gcc dot gnu dot org
@ 2010-01-17 23:46 ` janus at gcc dot gnu dot org
  2010-01-18 13:47 ` janus at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: janus at gcc dot gnu dot org @ 2010-01-17 23:46 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from janus at gcc dot gnu dot org  2010-01-17 23:46 -------
In addition to the parent component accessibility issue, there is also
something wrong with the error message being thrown in comment #0 and #1.

The check throwing this error resides in 'gfc_find_component', and was moved
there in r138275 by pault. Previously it was in
'gfc_match_structure_constructor', where it was probably more appropriate.

The error message is also thrown wrongly in extends_6.f03, where (again) no
structure constructor is involved.


-- 

janus at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |pault at gcc dot gnu dot org


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


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

* [Bug fortran/42545] type extension: parent component has wrong accessibility
  2009-12-29 18:38 [Bug fortran/42545] New: TBP: Wrongly reject inherite TBP with types with private components burnus at gcc dot gnu dot org
                   ` (3 preceding siblings ...)
  2010-01-17 23:46 ` janus at gcc dot gnu dot org
@ 2010-01-18 13:47 ` janus at gcc dot gnu dot org
  2010-01-18 14:36 ` burnus at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: janus at gcc dot gnu dot org @ 2010-01-18 13:47 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from janus at gcc dot gnu dot org  2010-01-18 13:46 -------
(In reply to comment #3)
> Here is a simple patch for setting the parent component accessibility:
> [...]
> This is probably not enough, since the access. specification of the parent type
> may come after the daughter type definition. But this already fixes the exmple
> in comment #2.

This version should be better:

Index: gcc/fortran/resolve.c
===================================================================
--- gcc/fortran/resolve.c       (revision 155994)
+++ gcc/fortran/resolve.c       (working copy)
@@ -10494,6 +10494,12 @@ resolve_fl_derived (gfc_symbol *sym)
          && resolve_typespec_used (&c->ts, &c->loc, c->name) == FAILURE)
        return FAILURE;

+      /* If this type is an extension, set the accessibility of the parent
+        component.  */
+      if (super_type && c == sym->components
+         && strcmp (super_type->name, c->name) == 0)
+       c->attr.access = super_type->attr.access;
+
       /* If this type is an extension, see if this component has the same name
         as an inherited type-bound procedure.  */
       if (super_type


It sets the accessibility at resolution time and makes the following variant of
comment #2 work:

module mo
  implicit none
  type :: tt
    integer :: i = 1
  end type
  type, extends(tt) :: ttt
    real :: x = 2.0
  end type
  private :: tt
end module
program pr
  use mo
  implicit none
  type(ttt) :: obj
  print *,obj%tt%i
end program


-- 


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


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

* [Bug fortran/42545] type extension: parent component has wrong accessibility
  2009-12-29 18:38 [Bug fortran/42545] New: TBP: Wrongly reject inherite TBP with types with private components burnus at gcc dot gnu dot org
                   ` (4 preceding siblings ...)
  2010-01-18 13:47 ` janus at gcc dot gnu dot org
@ 2010-01-18 14:36 ` burnus at gcc dot gnu dot org
  2010-01-18 14:39 ` 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-01-18 14:36 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from burnus at gcc dot gnu dot org  2010-01-18 14:36 -------
(In reply to comment #5)
> It sets the accessibility at resolution time and makes the following variant 
> of comment #2 work:

That variant works for me already with the trunk, i.e. it is not rejected which
is (for me) the expected result.

  * * *

As it took me a while to see whether the various examples are valid or not.
(Comment 0 is quite unrelated as it about TBP vs. component accessibility while
the rest is about accessibility of inherited components.)

Fortran 2003 has in "4.5.6.1 Inheritance":

"An extended type includes all of the type parameters, all of the components,
and the nonoverridden (4.5.6.2) nonfinal procedure bindings of its parent type.
These are said to be inherited by the extended type from the parent type. They
retain all of the attributes that they had in the parent type. Additional type
parameters, components, and procedure bindings may be declared in the
derived-type definition of the extended type."

"An extended type has a scalar, nonpointer, nonallocatable, parent component
with the type and type parameters of the parent type. The name of this
component is the parent type name. It has the accessibility of the parent
type."

"Note 4.51: Inaccessible components and bindings of the parent type are also
inherited, but they remain inaccessible in the extended type. Inaccessible
entities occur if the type being extended is accessed via use association and
has a private entity."


Thus the crucial part is:

a) For components "they retain all of the attributes that they had in the
parent type" -- thus the PRIVATE statement which only changes the default has
no influence.

b) For the parent type: If it is PRIVATE then also extended%parent%par_comp is
only accessible in the module per "It has the accessibility of the parent type"
in the second paragraph.
But what about: extended%par_comp ? par_comp is PUBLIC while its TYPE is
PRIVATE. Just from reading the standard, it looks valid.


-- 


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


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

* [Bug fortran/42545] type extension: parent component has wrong accessibility
  2009-12-29 18:38 [Bug fortran/42545] New: TBP: Wrongly reject inherite TBP with types with private components burnus at gcc dot gnu dot org
                   ` (5 preceding siblings ...)
  2010-01-18 14:36 ` burnus at gcc dot gnu dot org
@ 2010-01-18 14:39 ` burnus at gcc dot gnu dot org
  2010-01-19 13:20 ` janus at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: burnus at gcc dot gnu dot org @ 2010-01-18 14:39 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from burnus at gcc dot gnu dot org  2010-01-18 14:39 -------
(In reply to comment #6)
> > It sets the accessibility at resolution time and makes the following variant 
> > of comment #2 work:
> 
> That variant works for me already with the trunk, i.e. it is not rejected
> which is (for me) the expected result.

Actually, I misread "makes ... work": It is seemingly rejected with the patch
and - after (re)reading the standard (see quote in comment 6), I think
rejecting is indeed correct. Sorry for not checking that part of my comment
before hitting "Commit".


-- 


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


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

* [Bug fortran/42545] type extension: parent component has wrong accessibility
  2009-12-29 18:38 [Bug fortran/42545] New: TBP: Wrongly reject inherite TBP with types with private components burnus at gcc dot gnu dot org
                   ` (6 preceding siblings ...)
  2010-01-18 14:39 ` burnus at gcc dot gnu dot org
@ 2010-01-19 13:20 ` janus at gcc dot gnu dot org
  2010-01-19 13:45 ` janus at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: janus at gcc dot gnu dot org @ 2010-01-19 13:20 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from janus at gcc dot gnu dot org  2010-01-19 13:20 -------
Patch posted at:

http://gcc.gnu.org/ml/fortran/2010-01/msg00101.html


-- 

janus at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |janus at gcc dot gnu dot org
                   |dot org                     |
             Status|UNCONFIRMED                 |ASSIGNED
     Ever Confirmed|0                           |1
   Last reconfirmed|0000-00-00 00:00:00         |2010-01-19 13:20:04
               date|                            |


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


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

* [Bug fortran/42545] type extension: parent component has wrong accessibility
  2009-12-29 18:38 [Bug fortran/42545] New: TBP: Wrongly reject inherite TBP with types with private components burnus at gcc dot gnu dot org
                   ` (7 preceding siblings ...)
  2010-01-19 13:20 ` janus at gcc dot gnu dot org
@ 2010-01-19 13:45 ` janus at gcc dot gnu dot org
  2010-01-19 14:00 ` janus at gcc dot gnu dot org
  2010-02-07  3:45 ` hjl dot tools at gmail dot com
  10 siblings, 0 replies; 12+ messages in thread
From: janus at gcc dot gnu dot org @ 2010-01-19 13:45 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #9 from janus at gcc dot gnu dot org  2010-01-19 13:45 -------
Subject: Bug 42545

Author: janus
Date: Tue Jan 19 13:45:07 2010
New Revision: 156040

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=156040
Log:
gcc/fortran/
2010-01-19  Janus Weil  <janus@gcc.gnu.org>

        PR fortran/42545
        * resolve.c (resolve_fl_derived): Set the accessibility of the parent
        component for extended types.
        * symbol.c (gfc_find_component): Remove a wrongly-worded error message
        and take care of parent component accessibility.

gcc/testsuite/
2010-01-19  Janus Weil  <janus@gcc.gnu.org>

        PR fortran/42545
        * gfortran.dg/extends_6.f03: Modified an error message.
        * gfortran.dg/extends_10.f03: New test.
        * gfortran.dg/private_type_6.f03: Modified an error message.
        * gfortran.dg/structure_constructor_8.f03: Ditto.

Added:
    trunk/gcc/testsuite/gfortran.dg/extends_10.f03
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/resolve.c
    trunk/gcc/fortran/symbol.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/extends_6.f03
    trunk/gcc/testsuite/gfortran.dg/private_type_6.f90
    trunk/gcc/testsuite/gfortran.dg/structure_constructor_8.f03


-- 


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


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

* [Bug fortran/42545] type extension: parent component has wrong accessibility
  2009-12-29 18:38 [Bug fortran/42545] New: TBP: Wrongly reject inherite TBP with types with private components burnus at gcc dot gnu dot org
                   ` (8 preceding siblings ...)
  2010-01-19 13:45 ` janus at gcc dot gnu dot org
@ 2010-01-19 14:00 ` janus at gcc dot gnu dot org
  2010-02-07  3:45 ` hjl dot tools at gmail dot com
  10 siblings, 0 replies; 12+ messages in thread
From: janus at gcc dot gnu dot org @ 2010-01-19 14:00 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #10 from janus at gcc dot gnu dot org  2010-01-19 14:00 -------
Fixed with r156040. Closing.


-- 

janus at gcc dot gnu dot org changed:

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


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


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

* [Bug fortran/42545] type extension: parent component has wrong accessibility
  2009-12-29 18:38 [Bug fortran/42545] New: TBP: Wrongly reject inherite TBP with types with private components burnus at gcc dot gnu dot org
                   ` (9 preceding siblings ...)
  2010-01-19 14:00 ` janus at gcc dot gnu dot org
@ 2010-02-07  3:45 ` hjl dot tools at gmail dot com
  10 siblings, 0 replies; 12+ messages in thread
From: hjl dot tools at gmail dot com @ 2010-02-07  3:45 UTC (permalink / raw)
  To: gcc-bugs



-- 

hjl dot tools at gmail dot com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |4.5.0


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


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

end of thread, other threads:[~2010-02-07  3:45 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-12-29 18:38 [Bug fortran/42545] New: TBP: Wrongly reject inherite TBP with types with private components burnus at gcc dot gnu dot org
2010-01-17 22:35 ` [Bug fortran/42545] " janus at gcc dot gnu dot org
2010-01-17 22:42 ` [Bug fortran/42545] type extension: parent component has wrong accessibility janus at gcc dot gnu dot org
2010-01-17 23:35 ` janus at gcc dot gnu dot org
2010-01-17 23:46 ` janus at gcc dot gnu dot org
2010-01-18 13:47 ` janus at gcc dot gnu dot org
2010-01-18 14:36 ` burnus at gcc dot gnu dot org
2010-01-18 14:39 ` burnus at gcc dot gnu dot org
2010-01-19 13:20 ` janus at gcc dot gnu dot org
2010-01-19 13:45 ` janus at gcc dot gnu dot org
2010-01-19 14:00 ` janus at gcc dot gnu dot org
2010-02-07  3:45 ` hjl dot tools at gmail dot com

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