User account creation filtered due to spam.

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...
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.7.0
: P3 normal
Target Milestone: 4.7.0
Assignee: Not yet assigned to anyone
Keywords: rejects-valid
Depends on:
Reported: 2011-12-01 10:40 UTC by Tobias Burnus
Modified: 2016-11-16 14:25 UTC (History)
1 user (show)

See Also:
Known to work:
Known to fail:
Last reconfirmed:


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

" Inheritance
An extended type includes all of the type parameters, all of the components, and the nonoverridden ( 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
     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'
    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

2011-12-08  Tobias Burnus  <>

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

2011-12-08  Tobias Burnus  <>

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

Comment 2 Tobias Burnus 2011-12-08 20:03:16 UTC
FIXED on the trunk (4.7)