Note: This is a beta release of Red Hat Bugzilla 5.0. The data contained within is a snapshot of the live data so any changes you make will not be reflected in the production Bugzilla. Also email is disabled so feel free to test any aspect of the site that you want. File any problems you find or give feedback here.
Bug 453433 - warning: control reaches end of non-void function
Summary: warning: control reaches end of non-void function
Alias: None
Product: Red Hat Enterprise Linux 5
Classification: Red Hat
Component: gcc
Version: 5.1
Hardware: All
OS: Linux
Target Milestone: rc
: ---
Assignee: Jakub Jelinek
QA Contact: Petr Muller
Depends On:
TreeView+ depends on / blocked
Reported: 2008-06-30 16:05 UTC by Alan Matsuoka
Modified: 2016-09-20 02:04 UTC (History)
1 user (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Last Closed: 2009-08-31 21:15:00 UTC
Target Upstream Version:

Attachments (Terms of Use)

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) {

  main() {
     type2 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

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.


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.