Structure constructors for derived type with private components

If a derived type contains private components, it is impossible to use structure constructor in assignment. The standard requires that the constructor includes values for all components with the exception of those having default initializer or some complicated inheritance (C7100 (R756)). Obviously, it also requires that the component is accessible (C7103).

code example
module typ
  type point
    real :: x,y
    real, private :: angle
  end type point
...
end module typ

program main
  use typ
  type (point) :: p

  p = point(1.2,3.4)
  print '(g0)', p%x
end program main
$ gfortran struct_constr.f90
struct_constr.f90:12:7:

   12 |   p = point(1.2,3.4)
      |       1
Error: No initializer for component 'angle' given in the structure constructor at (1)

Would it really break anything if that rule were relaxed and did not apply to private components? After all, they are meant to be private, and as such, to be initialized and maintained through the module procedures only. On the other hand, assignment via single-component statements (object%component=value) for a rich type seems an overkill.

See my reply to Normal Kirby’s comment in Doctor Fortran in “Not My TYPE” - Doctor Fortran (stevelionel.com). I would expect the use of a constructor routine for a type with private components. It would look just like a constructor. In some cases, it may work to provide default initializers for those components.

Actually I read your post and the discussion before I started this topic. I just thought that the requirements of the standard here are a bit too stringent.

The idea of a structure constructor is that it constructs a complete value of that type. If the type owner wants a user to be able to use constructor syntax, they can export their own constructor routine.

I understand that. But on the other hand, there already are exceptions. If the type contains an allocatable array component, it is legally omitted in the constructor. And it is OK, standard conforming.

That’s fine. Allocatable arrays always have a defined status, either allocated or unallocated.