- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
In a project I am working on, I changed a fixed length string in a structure within a module to a deferred length string and the result was an internal compiler error (the code compiled and ran without issue before the change). I cannot reproduce the internal compiler error with a simple case, but I do get a segmentation fault in the below program when it hits the WRITE() statement. It is unclear to me what the issue is or if this is even related to the internal compiler error I was trying to reproduce. When compiling with '-std03', I get "warning #5436: Overlapping storage initializations encountered with S", so maybe it has something to do with the initialization, though I do not see multiple initializations here.
Fortran compiler version is Version 14.0.2.144 (64-bit), on Ubuntu 14.04 (beta).
The code is also attached:
MODULE stringmod TYPE, PUBLIC :: A CHARACTER(LEN=:), ALLOCATABLE :: string END TYPE TYPE(A), SAVE :: S = A('_test__TEST_') CONTAINS SUBROUTINE TestPrint() WRITE(*,*) S%string END SUBROUTINE END MODULE PROGRAM stringtest USE stringmod CALL TestPrint() END PROGRAM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If I may make one observation; it is not legal in a constant expression to initialize an allocatable component to anything other than a NULL().
Unfortunately, we did not diagnose that in 14.0.2, although that has been changed for a release coming later this year, resulting in this error:
stringtest.f90(5): error #6273: In a constant expression, the only value that may correspond to an allocatable component is a reference to NULL(). ['_test__TEST_']
TYPE(A), SAVE :: S = A('_test__TEST_')
-------------------------^
compilation aborted for stringtest.f90 (code 1)
So, this means that in your code, when TestPrint is called, S%String has not been allocated, and you see the run-time error reported.
Does this help?
--Lorri
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
If I may make one observation; it is not legal in a constant expression to initialize an allocatable component to anything other than a NULL().
Unfortunately, we did not diagnose that in 14.0.2, although that has been changed for a release coming later this year, resulting in this error:
stringtest.f90(5): error #6273: In a constant expression, the only value that may correspond to an allocatable component is a reference to NULL(). ['_test__TEST_']
TYPE(A), SAVE :: S = A('_test__TEST_')
-------------------------^
compilation aborted for stringtest.f90 (code 1)
So, this means that in your code, when TestPrint is called, S%String has not been allocated, and you see the run-time error reported.
Does this help?
--Lorri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Lori,
Glad to read the issue in Intel Fortran will be fixed in a release later this year. FWIW, gfortran 4.9 gives the following error:
gfortran.exe -JDebug\GNU\ -Wall -fall-intrinsics -g -std=f2008 -c C:\dev\Fortran\Test18\sor\TestFor.f90 -o Debug\GNU\sor\TestFor.o C:\dev\Fortran\Test18\sor\TestFor.f90:5.25: TYPE(A), SAVE :: S = A('_test__TEST_') 1 Error: Invalid initialization expression for ALLOCATABLE component 'string' in structure constructor at (1)
You may wish to check whether the new Intel Fortran version would give a message as clear-cut or a text that is even more informative for the developer.
Thanks,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thank you Lori.
Now that you mention it, I do recall trying to initialize allocatable components this way once before (years ago and not with deferred length strings), but compiler errors showed me the error of my ways. I seem to have forgotten in the years since and the lack of a compiler check failed to remind me. I am glad to hear the check will occur in future releases.
It sounds like this might be the source of the internal compiler error in my original project as I am attempting to do the same there.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page