[Bug c++/31545] No warning on missing return in if construct

2007-04-13 Thread walter at schreppers dot com


--- Comment #4 from walter at schreppers dot com  2007-04-13 11:36 ---
Apparantly this has been fixed in some newer version of g++. Keep up the good
work!


-- 

walter at schreppers dot com changed:

   What|Removed |Added

 Status|UNCONFIRMED |RESOLVED
 Resolution||FIXED


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31545



[Bug c++/31545] New: No warning on missing return in if construct

2007-04-12 Thread walter at schreppers dot com
This happens on other gcc versions too. It seems the checks on whether the
necessary return statement is used fail when using an if statement.
I included a little code snippet here. It compiles without warnings or errors
(all optimizations and even with -Wall no warnings are given). When executed it
crashes ofcourse because a function is called and return value expected which
is never pushed onto stack:

walter-schreppers-computer:~/ClassGen wschrep$ cat cppbug.cpp 

#include iostream
using namespace std;

class Test{
  public:
Test(){ fOk = false; }
~Test(){}

string indent(){
  return  ;
}

string faultyReturn(){
  if( !fOk )  indent();  //forgot return here (but compiler does not warn
me!)
  else return indent();
}

  private:
bool fOk;
};

int main(){
  cout  testing faulty class we forgot to return in member faultyReturn 
endl;
  cout  this should not compile, but it does and then crashes on runtime!
 endl;

  Test t;
  cout  '  t.faultyReturn()  '  endl;

  return 0;
}



walter-schreppers-computer:~/ClassGen wschrep$ g++ --version   
i686-apple-darwin8-g++-4.0.1 (GCC) 4.0.1 (Apple Computer, Inc. build 5367)
Copyright (C) 2005 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO

warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

walter-schreppers-computer:~/ClassGen wschrep$ g++ -Wall -O2 cppbug.cpp -o
cppbug
walter-schreppers-computer:~/ClassGen wschrep$ ./cppbug 

testing faulty class we forgot to return in member faultyReturn
this should not compile, but it does and then crashes!

Bus error


-- 
   Summary: No warning on missing return in if construct
   Product: gcc
   Version: 4.0.1
Status: UNCONFIRMED
  Severity: major
  Priority: P3
 Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: walter at schreppers dot com
 GCC build triplet: 5367
  GCC host triplet: i686-apple-darwin8
GCC target triplet: i686-apple-darwin8


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31545



[Bug c++/31545] No warning on missing return in if construct

2007-04-12 Thread walter at schreppers dot com


--- Comment #1 from walter at schreppers dot com  2007-04-12 10:55 ---
Created an attachment (id=13355)
 -- (http://gcc.gnu.org/bugzilla/attachment.cgi?id=13355action=view)
Compile with any optimization (i used -O2) 

A similar type of bug occured to me a lot in the past. When using if's
sometimes a warning is issued that a return statement is needed (even if it's
not the case, or rather there is a return issued in every part of the if
construct but compiler insists on writing another dummy return on the end of
function just to get rid of the warning when using -Wall). Might be related to
current problem where no warning or error is given when there really should be
because code will crash on runtime because of the missing return statement
(could be hard to find bug in a large project!).


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31545