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 <iostream>



        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;

        }

Reply via email to