[Bug c++/55189] New: g++ compiler does not report missing return on function with return type
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55189 Bug #: 55189 Summary: g++ compiler does not report missing return on function with return type Classification: Unclassified Product: gcc Version: 4.6.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ AssignedTo: unassig...@gcc.gnu.org ReportedBy: meanar...@gmail.com Compiled with MinGW port of g++, compiles without errors or warnings: g++ bug.cpp -o bug.exe Minimal sample bug.cpp: #include using namespace std; class Example { protected: int m_x; public: Example() { m_x = 0; } Example( const Example &ref ) { m_x = ref.m_x; } ~Example() { } int get() { return m_x; } void set( int x ) { m_x = x; } Example &operator =( Example ref ) { m_x = ref.m_x; return *this; } }; Example func( Example p ) { Example m; m.set( p.get() ); // ! COMPILER DOES NOT DETECT ABSENCE OF FUNCTION RETURN ! } int main() { Example m; m.set( 7 ); Example k; k = func( m ); // ! CONSEQUENTLY RESULT IS RANDOM ! cout << k.get() << endl; return 0; }
[Bug c++/55189] g++ compiler does not report missing return on function with return type
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55189 --- Comment #2 from meanone 2012-11-03 11:11:15 UTC --- (In reply to comment #1) > (In reply to comment #0) > > Compiled with MinGW port of g++, compiles without errors or warnings: > > It does warn if you ask it to: -Wall I can understand that this is ok behavior for C, but to have to EXPLICITLY ASK typesafe language like C++ to inform me if function WITH RETURN TYPE does not return anything ? If this is not bug why shouldn't we make int n; n =; printf("%d",n); to be legal code, compiler should simply assign whatever it wants. Right ? Could anyone explain what for should missing return on typical C++ function be useful at all ? Not to mention probability that it has been forgotten by mistake. -Wreturn-type should be set by default.