Bug 453433 - warning: control reaches end of non-void function
warning: control reaches end of non-void function
Status: CLOSED NOTABUG
Product: Red Hat Enterprise Linux 5
Classification: Red Hat
Component: gcc (Show other bugs)
5.1
All Linux
medium Severity medium
: rc
: ---
Assigned To: Jakub Jelinek
Petr Muller
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2008-06-30 12:05 EDT by Alan Matsuoka
Modified: 2016-09-19 22:04 EDT (History)
1 user (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2009-08-31 17:15:00 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Alan Matsuoka 2008-06-30 12:05:58 EDT
Description of problem:  In RHEL 5.1 , Under certain situations, the 4.1.2 g++
compiler does not report a warning that a non-void function does not return a
value when compiled with the -Wreturn-type compiler option.  The 3.2.3 g++
compiler works.

For example, given the following test program:

  // ******************** begin file.c ********************
  typedef struct struct1 {} type1;
  typedef struct struct2 {} type2;

  // this function should return an int but does not
  int functionNoReturnValue() {
  }

  void functionWrongTypedArguments(type1 t1) {
     return;
  }

  int
  main() {
     type2 t2;
  
     functionNoReturnValue();
     functionWrongTypedArguments(t2);
     return 0;
  }
  // ******************** end file.c ********************

try compiling as follows:

  % g++ -Wreturn-type file.c

output from v4.1.2 is as follows:

  file.c: In function 'int main()':
  file.c:16: error: conversion from 'type2' to non-scalar type 'type1' requested

Note the above has *no* warning message about control reaches end of non-void
function.

output from v3.2.3 is as follows:  

  % g++ -Wreturn-type file.c

  file.c: In function `int functionNoReturnValue()':
  file.c:5: warning: control reaches end of non-void function
  file.c: In function `int main()':
  file.c:16: conversion from `type2' to non-scalar type `struct1' requested

Note the above control reaches end of non-void function warning.

How reproducible: Very much

Steps to Reproduce: try the above code

Actual results: no warning

Expected results: warning displayed

Additional info:

Hi Heath,
         Here are the two resposes from our developers hope they are good enough
reasons to get this fixed.

1)I'd first note that Solaris reports this as an ERROR. Engineers use Linux as
development platform and CM builds  encounter on all ports. Since Linux does not
detect this prior to  engineers' check-in, CM can not build Solaris . That
impacts CM  productivity and overall build turn-around time. Also, it's a 
regression from v3.2.3. We need this to be fixed.

2)Also, the warning catches a class of incorrect programs.  Calling functions
get an invalid return value leading to possible memory corruption and incorrect
results.  Productivity improves if this is caught up-front helping Cadence and
the entire Linux community.


regards
Satya

SEG Notes:

The warning shows up at different levels of optimization.
With gcc it always gets issued. With g++ it only gets displayed with -O3.
Cadence considers this to be a regression from the 3.x compilers.

Note You need to log in before you can comment on or make changes to this bug.