The following C++ code compiles and executes correctly:

#include <iostream>
using namespace std;
class Base
{
        int     i;

public:

        Base(): i( -1 ) { cout << "Base()" << endl; }
        Base( int a ) : i( a ) { cout << "Base(int), i: " << i << endl; }
        Base( Base& b ) { i = b.i; cout << "Base(Base&), i: " << i << endl; }
        Base& operator = ( Base& b )
        {
                i = b.i;
                cout << "Base::operator =(), i: " << i << endl;
//              return *this;
        }
        virtual ~Base(){}
        operator int() { cout << "Base::operator int()" << endl; return i; }
};
void test1()
{
        cout << endl << "Example 1" << endl;
        Base b1;
        cout << "b1: " << b1 << endl;

        cout << endl << "Example 2" << endl;
        Base b2 = Base( 5 );
        cout << "b2: " << b2 << endl;

        cout << endl << "Example 3" << endl;
        Base b3(6);
        cout << "b2: " << b3 << endl;

        cout << endl << "Example 4" << endl;
        Base b4 = b1;
        cout << "b4: " << b4 << endl;

        cout << endl << "Example 5" << endl;
        Base b5; b5 = b2;
        cout << "b5: " << b5 << endl;
}
int main( int argc, char** argv )
{
        test1();
}
/////////////////////////////////////////////////////

But the operator =() does not return a value! This error is caught by MS Visual
Studio.


-- 
           Summary: No return value from operator =() is accepted by the
                    compiler
           Product: gcc
           Version: 4.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: Curatica at gmail dot com
 GCC build triplet: What is this?
  GCC host triplet: Linux lambrusco 2.6.16.13-4-smp #1 SMP Wed May 3
                    04:53:23 UTC 20
GCC target triplet: What is this?


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

Reply via email to