Commit Message

Dear all,
attached is a draft patch for Fortran 2003's constructors. By
constructors, I mean a generic function which has the same name as a
derived type and which can be used in place of a structure constructor.
If the generic function returns the derived type, it resembles the
constructor functions of C++; however, the generic function might also
just return an integer and have no relation/knowledge of the derived
type. (Only) if no suitable generic function is available, the structure
constructor is used.
The attached patch is nearly ready. Thus, I would like to have feedback
on the implementation. Additionally, I would be happy if someone could
test it as the patch could potentially break any Fortran code which uses
derived types - and it might not handle all valid constructor code
either. Especially with invalid code there can be issues.
The patch is not yet cleaned up; I also need to write a changelog. For
the status and possibly updated versions of the patch, see also
https://userpage.physik.fu-berlin.de/~tburnus/tmp/constructor.diff
While the patch should have no major regressions nor missing features,
it is not yet regression free. Currently known issues (see link above
for details):
- gfortran.dg/class_21.f03: ICE on valid code.
- gfortran.dg/coarray_lock_3.f90 and coarray_lock_4.f90: The dg-error
message changed.
- fortran.dg/result_1.f90: Ditto.
- constructor_4.f90: (new test) Missing -std=f95 diagnostic
- [no test] Missing ambiguous check
- (Known, unrelated failures: realloc_on_assign_5.f03,
select_type_12.f03, entry_4.f90)
Internal implementation:
* For derived types, a generic-function symbol is generated
* Additionally, a symbol is generated for FL_DERIVED with the same
sym->name but where the symtree->name has the first letter of the name
uppercased. This is included in the sym->generic list of previous symbol.
* At resolve time, if not suitable generic function could be found, a
structure constructor is assumed.
* The main issue is to have FL_DERIVED available where needed and to
ensure that with module loading always both symbols are loaded.
* I had to modify iso_c_binding a bit, which resulted in fixing PR 37829
and 45190.
Tobias
PS: I have tested the patch with some real-word codes, though not all
with the latest patch version. I do not expect major issues, but I do
expect that some programs will fail. Hopefully, most remaining issues
can be found before 4.7.0 is released.