Bug 51378 - [OOP] Structure constructor wrongly rejects parent components if only child has PRIVATE comps
Summary: [OOP] Structure constructor wrongly rejects parent components if only child h...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.7.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2011-12-01 10:40 UTC by Tobias Burnus
Modified: 2011-12-08 20:03 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tobias Burnus 2011-12-01 10:40:28 UTC
Found in Reinhold Bader's testsuite (partial_construct_01_pos.f90). The following program is rejected by crayftn and gfortran with:

  Derived type "L_VEC" has private components, therefore a structure constructor must not be defined for this type.

and with 

  o_l_vec = l_vec(comp=(/1.0, 2.0, 3.0/),len=3)
            1
  Error: Component 'comp' at (1) is a PRIVATE component of 'l_vec'

The program is accepted by ifort 12. The question is whether "COMP" and "LEN" are private or not. If they are not and only "label" is private, the program is valid as the following is not violated (quote from F2008):

"C495 (R455) The type name and all components of the type for which a component-spec appears shall be accessible in the scoping unit containing the structure constructor."

And the following guarantees that they remain accessible even if the extension uses a "PRIVATE" statement:

"4.5.7.2 Inheritance
An extended type includes all of the type parameters, all of the components, and the nonoverridden (4.5.7.3) type-bound procedures of its parent type. These are inherited by the extended type from the parent type. They retain all of the attributes that they had in the parent type."


module type_ext
  type :: vec
     real, dimension(3) :: comp
     integer :: len
  end type vec
  type, extends(vec) :: l_vec
     private
     character(len=20) :: label = '01234567890123456789'
  end type l_vec
end module type_ext
program test_ext
  use type_ext
  implicit none
  type(vec) :: o_vec, oo_vec
  type(l_vec) :: o_l_vec
  integer :: i
!
  o_vec = vec((/1.0, 2.0, 3.0/),3)
!  write(*,*) o_vec%comp, o_vec%len
  o_l_vec = l_vec(comp=(/1.0, 2.0, 3.0/),len=3)
! partial constr. not accepted by ifort 11.1, fixed in 12.0 (issue 562240)
!  write(*,*) o_l_vec%comp, o_l_vec%len
!  write(*,*) o_l_vec%vec
  oo_vec = o_l_vec%vec
  do i=1, 3
    if (abs(oo_vec%comp(i) - o_vec%comp(i)) > 1.0E-5) then
       write(*, *) 'FAIL'
       stop
    end if
  end do
  write(*, *) 'OK'
end program
Comment 1 Tobias Burnus 2011-12-08 18:57:01 UTC
Author: burnus
Date: Thu Dec  8 18:56:58 2011
New Revision: 182133

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

        PR fortran/51378
        * symbol.c (gfc_find_component): Fix access check of parent
        components.

2011-12-08  Tobias Burnus  <burnus@net-b.de>

        PR fortran/51378
        * gfortran.dg/private_type_14.f90: New.


Added:
    trunk/gcc/testsuite/gfortran.dg/private_type_14.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/symbol.c
    trunk/gcc/testsuite/ChangeLog
Comment 2 Tobias Burnus 2011-12-08 20:03:16 UTC
FIXED on the trunk (4.7)