[Bug fortran/43256] New: [OOP] character-valued TBP with missing optional arg
janus at gcc dot gnu dot org
gcc-bugzilla@gcc.gnu.org
Thu Mar 4 15:44:00 GMT 2010
Consider the following code:
module module_myobj
implicit none
type :: myobj
contains
procedure :: myfunc
end type
contains
function myfunc(this, status)
class(myobj), intent(in) :: this
integer, intent(out), optional :: status
character(len=80) :: myfunc
if (present(status)) then
write (*,*) 'myfunc: status is present.'
else
write (*,*) 'myfunc: status is not present.'
end if
myfunc = ' '
end function
end module
program test_optional
use :: module_myobj
implicit none
character(len=80) :: res
integer :: status
type(myobj) :: myinstance
res = myfunc(myinstance) ! OK
res = myfunc(myinstance, status) ! OK
res = myinstance%myfunc() ! FAILED
res = myinstance%myfunc(status) ! OK
end program
This currently produces the output:
myfunc: status is not present.
myfunc: status is present.
myfunc: status is present.
myfunc: status is present.
The correct output would be:
myfunc: status is not present.
myfunc: status is present.
myfunc: status is not present.
myfunc: status is present.
Apparently this only happens for type-bound character-valued functions (but not
for subroutines or e.g. integer-valued functions).
-fdump-tree-original shows the following for the four calls to 'myfunc':
myfunc ((character(kind=1)[1:80] *) &str.3, 80, &class.2, 0B);
myfunc ((character(kind=1)[1:80] *) &str.5, 80, &class.4, &status);
myfunc ((character(kind=1)[1:80] *) &str.7, 80, &class.6);
myfunc ((character(kind=1)[1:80] *) &str.9, 80, &class.8, &status);
In the third case we fail to pass a null pointer for the missing optional arg.
--
Summary: [OOP] character-valued TBP with missing optional arg
Product: gcc
Version: 4.5.0
Status: UNCONFIRMED
Keywords: wrong-code
Severity: normal
Priority: P3
Component: fortran
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: janus at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=43256
More information about the Gcc-bugs
mailing list