🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.g++.bug
Article #239

Copy constructor/operator= generation not done

#239
From: Jason Merrill
Date: Sun, 12 Apr 1992 06:19
42 lines
1868 bytes
Situation #1:

If some constructors are defined and the copy constructor isn't, g++
assumes that it doesn't exist, such that the call 

new classname(*this);

generates an error such as

Dictionary.c: In method `class Object* Dictionary::shallowCopy ()const ':
Dictionary.c:43: bad argument 0 for function `Dictionary::Dictionary
  (unsigned int (=  DEFAULT_CAPACITY ))' (type was class Dictionary)

(The code that produced this error is in the NIHCL v3.0, Object.h and
Dictionary.[ch]; I can send it to you on request)

Solution:  Declare classname(classname&) explicitly.

Situation #2:

If operator= is not defined for class A and class B calls A::operator=, an
error such as

Dictionary.c: In method `void  Dictionary::operator = (const class
  Dictionary&)':
Dictionary.c:51: no member function `Set::operator ='

is generated.  Although operator= is not inherited exactly, it still needs
to be defined implicitly.  Rules for generating the implicit operator= can
be found in the ARM, section 12.8.

Again, declaring operator=(classname&) explicitly solves the problem.

Again, the pertinent code is in Object.h, Dictionary.[ch] and Set.h.  In
fact, the operator= that should be called eventually is the one in ArrayOb.

I see this as a serious bug, albeit one with a simple workaround.  I also
believe that the two problems have a single cause...

--
Jason Merrill
jason@jarthur.claremont.edu
Technical Details
Message-ID: <1992Apr12.061917.15653@muddcs.claremont.edu>
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!jarthur.claremont.edu!jason

Show Full Headers
Complete Article Headers
Newsgroups: gnu.g++.bug
Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!jarthur.claremont.edu!jason
From: jason@jarthur.claremont.edu (Jason Merrill)
Subject: Copy constructor/operator= generation not done
Message-ID: <1992Apr12.061917.15653@muddcs.claremont.edu>
Sender: gnulists@ai.mit.edu
Organization: Harvey Mudd College
Distribution: gnu
Date: Sun, 12 Apr 1992 06:19:17 GMT
Approved: bug-g++@prep.ai.mit.edu
Lines: 43