The C++ code: #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 = 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(); } ///////////////////////////////////////////////////// The compile command: g++ construction.cc -o construction Compilation errors: construction.cc: In function 'void test1()': construction.cc:28: error: no matching function for call to 'Base::Base(Base), construction.cc:11: note: candidates are: Base::Base(Base&) construction.cc:10: note: Base::Base(int) construction.cc:28: error: initializing temporary from result of 'Base::Base(int)' We believe that Base b2 = 5; should call Base::Base( int ). The same code compiles and executes fine under Microsoft Visual Studio. -- Summary: Conversion Constructor not accepted/recognized 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: Not sure what this means; here is the result of uname - a: Linux GCC target triplet: What is this? http://gcc.gnu.org/bugzilla/show_bug.cgi?id=42470