This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
["Paul Price" <slxzz@cc.usu.edu>: unsubscribe]
- To: bug-gcc at gnu dot org
- Subject: ["Paul Price" <slxzz@cc.usu.edu>: unsubscribe]
- From: Paul Morris <pmorris at ptolemy dot arc dot nasa dot gov>
- Date: Fri, 26 May 2000 17:05:39 PDT
My gnats report (entered through the web page) seems to have been
misdirected?
---------------
Reply-To: <paul@xpit.com>
From: "Paul Price" <slxzz@cc.usu.edu>
To: <pmorris@ptolemy.arc.nasa.gov>
Subject: unsubscribe
Date: Fri, 26 May 2000 17:48:26 -0700
-----Original Message-----
From: gnats-prs-owner@sourceware.cygnus.com
[mailto:gnats-prs-owner@sourceware.cygnus.com]On Behalf Of
pmorris@ptolemy.arc.nasa.gov
Sent: Friday, May 26, 2000 3:28 PM
To: gnats-gnats@sourceware.cygnus.com
Cc: wedgingt@ptolemy.arc.nasa.gov
Subject: gnats/78: g++ 2.95.2 copies without constructor, then calls
destructor
>Number: 78
>Category: gnats
>Synopsis: g++ 2.95.2 copies without constructor, then calls
destructor
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Fri May 26 15:34:00 PDT 2000
>Closed-Date:
>Last-Modified:
>Originator: Paul Morris and Will Edgington
>Release: g++-2.95.2 and earlier
>Organization:
>Environment:
Sun Ultra 2 SunOS 5.6 (Solaris)
>Description:
g++ compiles incorrectly. Under certain circumstances, it
creates a copy without calling the copy constructor, and
later passes the copy to the destructor. This can cause
reference-count schemes to prematurely release storage.
>How-To-Repeat:
Enclosed is a self-contained program that exercises the bug,
with print statements to illustrate the problem.
Note that the refCount goes to -1.(If the SUNWspro compiler
is used instead, the refCount correctly ends at 0.)
PRINTOUT FROM EXAMPLE PROGRAM
Created tag 1 item
refCount now 1
Created tag 2 item as copy of tag 1 item
refCount now 2
Created tag 3 item
Assigned tag 3 item as copy of tag 2 item
refCount now 3
Descoped tag 2 item
refCount now 2
Created tag 4 item as copy of tag 3 item
refCount now 3
Created tag 5 item
Assigned tag 5 item as copy of tag 4 impostor
refCount now 4
Descoped tag 4 impostor
refCount now 3
Descoped tag 4 item
refCount now 2
Descoped tag 5 item
refCount now 1
Descoped tag 3 item
refCount now 0
Descoped tag 1 item
refCount now -1
>Fix:
The compiler needs to be modified to call the copy
constructor when it makes the copy identified as the
"impostor" in the example printout.
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: application/octet-stream; name="test.cc"
Content-Transfer-Encoding: text
Content-Disposition: attachment; filename="test.cc"
#include <iostream.h>
class ModId {
public:
ModId (int datum = 0);
ModId(const ModId& org);
ModId& operator=(const ModId& org);
~ModId ();
char* judge() const;
private:
int tag;
int datum;
int* refCount;
};
int topTag = 1;
ModId* tagPtr[1000];
char* ModId::judge() const
{ return (this == tagPtr[this->tag]) ? " item " : " impostor "; }
ModId::ModId (int dat)
{
tagPtr[tag = topTag++] = this;
datum = dat;
*(refCount = new int) = 1;
cerr << "Created tag " << tag << judge() << "\n";
if (datum) cerr << " refCount now " << *refCount << "\n";
}
ModId::ModId(const ModId& org)
{
tagPtr[tag = topTag++] = this;
datum = org.datum;
(*(refCount = org.refCount))++;
cerr << "Created tag " << tag << judge() << "as copy of tag " << org.tag
<< org.judge() << "\n";
if (datum) cerr << " refCount now " << *refCount << "\n";
}
ModId::~ModId ()
{
(*refCount)--;
cerr << "Descoped tag " << tag << judge() << "\n";
if (datum) cerr << " refCount now " << *refCount << "\n";
}
ModId& ModId::operator=(const ModId& org)
{
(*org.refCount)++;
(*refCount)--;
cerr << "Assigned tag " << tag << judge() << "as copy of tag " << org.tag
<< org.judge() << "\n";
if (datum && org.datum)
cerr << " refCount unchanged" << *refCount << "\n";
else if (datum) cerr << " refCount now " << *refCount << "\n";
else if (org.datum) cerr << " refCount now " << *(org.refCount) << "\n";
refCount = org.refCount;
datum = org.datum;
// Tag itself not copied -- unique to each instance
return *this;
}
class VarEntry {
public:
ModId mod;
VarEntry (ModId p) { mod = p; }
VarEntry () { }
};
class pseudoTT {
ModId mod;
public:
pseudoTT (ModId p) { mod = p; }
pseudoTT () { }
};
VarEntry copy (const VarEntry& var) { return var; }
int main()
{
ModId foo(1);
VarEntry v(foo);
pseudoTT var = pseudoTT(copy(v).mod);
}