Bug 453433

Summary: warning: control reaches end of non-void function
Product: Red Hat Enterprise Linux 5 Reporter: Alan Matsuoka <alanm>
Component: gccAssignee: Jakub Jelinek <jakub>
Status: CLOSED NOTABUG QA Contact: Petr Muller <pmuller>
Severity: medium Docs Contact:
Priority: medium    
Version: 5.1CC: ohudlick
Target Milestone: rc   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2009-08-31 21:15:00 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Alan Matsuoka 2008-06-30 16:05:58 UTC
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.