I came across some weird behavior when trying to use the explicit keyword on a copy constructor. Take the example code below:

Code:
class myint {
    int x;
public:
    myint();
    explicit myint(int i);
    explicit myint(const myint &i);
    myint &operator=(int i);
    myint &operator=(const myint &i);
    const myint operator+(int i);
    const myint operator+(const myint &i);
    const myint operator-(int i);
    const myint operator-(const myint &i);
    myint &operator+=(int i);
    myint &operator+=(const myint &i);
    myint &operator-=(int i);
    myint &operator-=(const myint &i);
};

myint::myint()
{
    x=0;
}

myint::myint(int i)
{
    x=i;
}

myint::myint(const myint &i)
{
    x=i.x;
}

myint &myint::operator=(int i)
{
    x=i;
    return *this;
}

myint &myint::operator=(const myint &i)
{
    x=i.x;
    return *this;
}

const myint myint::operator+(int i)
{
    return myint(x+i);
}

const myint myint::operator+(const myint &i)
{
    return myint(x+i.x);
}

const myint myint::operator-(int i)
{
    return myint(x-i);
}

const myint myint::operator-(const myint &i)
{
    return myint(x-i.x);
}

myint &myint::operator+=(int i)
{
    return *this=*this+i;
}

myint &myint::operator+=(const myint &i)
{
    return *this=*this+i;
}

myint &myint::operator-=(int i)
{
    return *this=*this-i;
}

myint &myint::operator-=(const myint &i)
{
    return *this=*this-i;
}

int main()
{
    myint a,b(3);
    myint c(b);
    myint *d = new myint(4);

    a=b+c;
    a=b+0;
    delete d;
    return 0;
}
This compiles fine with Sun's compiler (CC: Sun C++ 5.8 2005/10/13). But if I try to compile with the GNU compiler (3.4.6 and 4.1.2), it gives me this:

Code:
x5.cpp: In member function `const myint myint::operator+(int)':
x5.cpp:50: error: no matching function for call to `myint::myint(myint)'
x5.cpp: In member function `const myint myint::operator+(const myint&)':
x5.cpp:55: error: no matching function for call to `myint::myint(myint)'
x5.cpp: In member function `const myint myint::operator-(int)':
x5.cpp:60: error: no matching function for call to `myint::myint(myint)'
x5.cpp: In member function `const myint myint::operator-(const myint&)':
x5.cpp:65: error: no matching function for call to `myint::myint(myint)'
x5.cpp: In member function `myint& myint::operator+=(int)':
x5.cpp:70: error: no matching function for call to `myint::myint(const myint)'
x5.cpp: In member function `myint& myint::operator+=(const myint&)':
x5.cpp:75: error: no matching function for call to `myint::myint(const myint)'
x5.cpp: In member function `myint& myint::operator-=(int)':
x5.cpp:80: error: no matching function for call to `myint::myint(const myint)'
x5.cpp: In member function `myint& myint::operator-=(const myint&)':
x5.cpp:85: error: no matching function for call to `myint::myint(const myint)'
x5.cpp: In function `int main()':
x5.cpp:94: error: no matching function for call to `myint::myint(const myint)'
x5.cpp:95: error: no matching function for call to `myint::myint(const myint)'
I tried removing "explicit" from the copy constructor and stepping through the code in gdb, but it does seem to call this function at all at these points.

Any idea what's going on here? You would think something like this wouldn't differ between compilers.