Bug 52843

Summary: Unexpected rejection of pure recursive function
Product: gcc Reporter: Fran Martinez Fadrique <fmartinez>
Component: fortranAssignee: Not yet assigned to anyone <unassigned>
Status: RESOLVED FIXED    
Severity: normal CC: burnus, quantheory
Priority: P3    
Version: 4.7.1   
Target Milestone: ---   
Host: Target:
Build: Known to work:
Known to fail: Last reconfirmed:
Bug Depends on:    
Bug Blocks: 45170    
Attachments: Sample code for bug

Description Fran Martinez Fadrique 2012-04-03 14:22:54 UTC
Created attachment 27074 [details]
Sample code for bug

When a functions returns a string declared as character(len=:), allocatable the compiler complains about the function not allowed to be pure or recursive.

The attached file produces the following diagnostics (note that messages appear twice):


fmmf@porfmmf:~/gfortran_bugs/pure_returns_character_allocatable$ /opt/gcc-4.7/bin/gfortran -c m_module.f90 
m_module.f90:31:

pure function f_p( x ) result(res)
1
Error: CHARACTER(*) function 'f_p' at (1) cannot be pure
m_module.f90:20:

recursive function f_r( x ) result(res)
1
Error: CHARACTER(*) function 'f_r' at (1) cannot be recursive
m_module.f90:8:

recursive pure function f_r_p( x ) result(res)
1
Error: CHARACTER(*) function 'f_r_p' at (1) cannot be pure
m_module.f90:8:

recursive pure function f_r_p( x ) result(res)
1
Error: CHARACTER(*) function 'f_r_p' at (1) cannot be recursive
m_module.f90:31:

pure function f_p( x ) result(res)
1
Error: CHARACTER(*) function 'f_p' at (1) cannot be pure
m_module.f90:20:

recursive function f_r( x ) result(res)
1
Error: CHARACTER(*) function 'f_r' at (1) cannot be recursive
m_module.f90:8:

recursive pure function f_r_p( x ) result(res)
1
Error: CHARACTER(*) function 'f_r_p' at (1) cannot be pure
m_module.f90:8:

recursive pure function f_r_p( x ) result(res)
1
Error: CHARACTER(*) function 'f_r_p' at (1) cannot be recursive
Comment 1 Tobias Burnus 2012-05-12 09:54:00 UTC
Author: burnus
Date: Sat May 12 09:53:53 2012
New Revision: 187427

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=187427
Log:
2012-05-12  Tobias Burnus  <burnus@net-b.de>

        PR fortran/49110
        PR fortran/52843
        * resolve.c (resolve_fl_procedure): Don't regard
        character(len=:) as character(*) in the diagnostic.

2012-05-12  Tobias Burnus  <burnus@net-b.de>

        PR fortran/49110
        PR fortran/52843
        * gfortran.dg/deferred_type_param_5.f90: New.


Added:
    trunk/gcc/testsuite/gfortran.dg/deferred_type_param_5.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/resolve.c
    trunk/gcc/testsuite/ChangeLog
Comment 2 Tobias Burnus 2012-05-12 09:56:45 UTC
FIXED on the trunk.

Thanks for the bugreport and sorry for the delay.
Comment 3 Sean Santos 2012-10-24 20:59:54 UTC
I see that the bug fix for this is on the trunk, but not on the 4.7 branch. I was confused because I was still experiencing this bug in a 4.7.3 prerelease, until I realized that the fix was committed after 4.7 was split off.