Bug 33950 - Warning missing for function result not set
Summary: Warning missing for function result not set
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.3.0
: P3 enhancement
Target Milestone: 4.4.0
Assignee: Daniel Franke
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2007-10-30 16:27 UTC by Francois-Xavier Coudert
Modified: 2008-02-28 20:28 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2008-01-29 10:14:26


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Francois-Xavier Coudert 2007-10-30 16:27:07 UTC
In the first case below, a warning should be emitted just the same as the second case... Types other than character are not affected, because for them the middle-end will do the job anyway.

$ cat s.f90
function pop() result(item)
  character(len=0) :: item
end function pop
$ gfortran s.f90 -c
$ cat t.f90
function pop()
  character(len=1) :: pop
end function pop
$ gfortran t.f90 -c
t.f90: In function ‘pop’:
t.f90:1: warning: Function does not return a value
Comment 1 Daniel Franke 2008-01-29 10:14:26 UTC
See patch in PR31463. Output for testcases:

$> gfortran-svn -g -c -Wall pr33950-1.f90
pr33950-1.f90:1.27:

function pop() result(item)
                          1
Warning: Return value 'item' of function 'pop' declared at (1) not set

$> gfortran-svn -g -c -Wall pr33950-2.f90
pr33950-2.f90:1:

function pop()
1
Warning: Return value of function 'pop' at (1) not set
Comment 2 Daniel Franke 2008-02-28 20:23:45 UTC
Subject: Bug 33950

Author: dfranke
Date: Thu Feb 28 20:22:55 2008
New Revision: 132756

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=132756
Log:
gcc/fortran:
2008-02-28  Daniel Franke  <franke.daniel@gmail.com>

        PR fortran/31463
        PR fortran/33950
        PR fortran/34296
        * lang.opt: Added -Wreturn-type.
        * options.c (gfc_handle_option): Recognize -Wreturn-type.
        * trans-decl.c (gfc_trans_deferred_vars): Emit warnings for funtions
        where the result value is not set.
        (gfc_generate_function_code): Likewise.
        (generate_local_decl): Emit warnings for funtions whose RESULT
        variable is not set.

gcc/testsuite:
2008-02-28  Daniel Franke  <franke.daniel@gmail.com>

        PR fortran/31463
        PR fortran/33950
        PR fortran/34296
        * gfortran.dg/arrayio_11.f90: Fixed test.
        * gfortran.dg/arrayio_12.f90: Likewise.
        * gfortran.dg/module_read_1.f90: Added warning-directives.
        * gfortran.dg/pr32242.f90: Likewise.
        * gfortran.dg/result_in_spec_3.f90: Likewise.
        * gfortran.dg/use_12.f90: Likewise.
        * gfortran.dg/warn_function_without_result.f90 : New test.


Added:
    trunk/gcc/testsuite/gfortran.dg/warn_function_without_result.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/lang.opt
    trunk/gcc/fortran/options.c
    trunk/gcc/fortran/trans-decl.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/gfortran.dg/arrayio_11.f90
    trunk/gcc/testsuite/gfortran.dg/arrayio_12.f90
    trunk/gcc/testsuite/gfortran.dg/module_read_1.f90
    trunk/gcc/testsuite/gfortran.dg/pr32242.f90
    trunk/gcc/testsuite/gfortran.dg/result_in_spec_3.f90
    trunk/gcc/testsuite/gfortran.dg/use_12.f90

Comment 3 Daniel Franke 2008-02-28 20:25:52 UTC
Fixed in trunk. Closing.