error in g++ error report

Gabriel Dos Reis Gabriel.Dos-Reis@dptmaths.ens-cachan.fr
Mon Sep 1 15:06:00 GMT 1997


>>>>> «Nelson», Nelson Jose dos Santos Ferreira <Nelson.Ferreira@inesc.pt> wrote:

Nelson> On Fri, 29 Aug 1997 10:00:36 +0200 (MET DST), Gabriel Dos Reis (aka "Gabriel"),
Nelson> regarding 'error in g++ error report', said: 

[...]

Gabriel> A::A(A) is not a constructor and one cannot declare such a function. So
Gabriel> why is g++ trying to call A::A(A) ?

Nelson> You should have declared the copy constructor as:

Nelson> A( const A& ) {}


	The omission was delibarate. The intent was to prevent
initialization with const object. And g++ fails to correctly handle
this code. It should have reported that the constructor A(const A&)
was unreachable.


Nelson> Since you didn't the const A a will prevent from calling your "copy
Nelson> constructor". The matching rules of C++ say that a const object may be passed
Nelson> to a function by value (taking a temporary object). 


	They also said that copy constructors always take a reference (not
a value), so g++ should not even attempt to call  A::A(A) which is not
a copy constructor.


-- Gaby




More information about the Gcc mailing list