This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: error in g++ error report
- To: Nelson Jose dos Santos Ferreira <Nelson dot Ferreira at inesc dot pt>
- Subject: Re: error in g++ error report
- From: Gabriel Dos Reis <Gabriel dot Dos-Reis at dptmaths dot ens-cachan dot fr>
- Date: Tue, 2 Sep 1997 12:22:39 +0200 (MET DST)
- Cc: egcs at cygnus dot com
- References: <199708290800.KAA07042@piano.dptmaths.ens-cachan.fr><8767smji42.fsf@sourcebase.linux.pt><199709012202.AAA05246@cor.dptmaths.ens-cachan.fr><2xd8msw222.fsf@ccae-sv.inesc.pt><199709020947.LAA05859@cor.dptmaths.ens-cachan.fr><2xwwl0uj7e.fsf@ccae-sv.inesc.pt>
>>>>> «Nelson», Nelson Jose dos Santos Ferreira <Nelson.Ferreira@inesc.pt> écrit :
Nelson> On Tue, 2 Sep 1997 11:47:10 +0200 (MET DST), Gabriel Dos Reis (aka "Gabriel"),
Nelson> regarding 'Re: error in g++ error report', said:
Nelson> You should have declared A(A&) then.
Gabriel> Did you read the code I included ?
Nelson> Not on my second reply.
Here it is:
class A {
public:
A() {}
A(A&) {}
};
int main()
{
const A a;
A b = a;
}
Gabriel> The draft is clear. If you do not declare a copy constructor
Gabriel> then the compiler generate one with bitwise copy semantic, whose
Gabriel> signature is:
Gabriel> A(const A&)
Gabriel> If at least one copy constructor is declared then it overrides the
Gabriel> default one unless it is defined. I am afraid you didn't get the
Gabriel> purpose of the code. Please read Alexandre Oliva's reply.
Nelson> How does this conflict with my answer ? I only said one answer would be for
Nelson> you to declare the copy constructor as private. Then the compiler will not
Nelson> generate the bitwise copy constructor!
You 're right in saying that, but the compiler is wrong in
attempting to generate a copy constructor since there is already one!
If it is not suitable then it must give up with an appropriate
error-message. Take a look at the CD2 section 12.8.
Nelson> Probably I didn't get the purpose.
My purpose was to see how g++ does handles this case. If I
want to initialize with non-const objects (but not with const objects)
then I can define only A(A&) and live A(const A&) not delcared. I do
not have to declare A(const A&) private. I should to so if no copy
constructor were declared
Best,
-- Gaby