RE: [sv-ec] A question about copy constructors

From: Arturo Salz <Arturo.Salz_at_.....>
Date: Fri Jan 19 2007 - 12:47:17 PST
> So to require an error would not be backwards compatible with the
> current LRM.

Since the behavior is open to interpretation, this is not a backward
compatibility issue. At best, the LRM is ambiguous and must be
clarified, which is what I believe we're debating now. Certainly, I (as
well as other people) never read the LRM as allowing a null object.

> But I suspect people are more interested in what the *desirable*
> behavior should be. If we take an analogy from C, malloc(0) returns a
> null pointer and is not an exception case.

Actually, the behavior of malloc(0) is the topic of some debate, and it
is certainly not as simplistic as you think. The standard (n869.txt)
does say:

	If the size of the space requested is zero, the behavior is
	implementation-defined: either a  null pointer  is returned,
	or the behavior is as if the size were some nonzero value,
	except that the returned  pointer  shall not  be  used  to
	access an object.

If you consult the man page, different versions of libc use similar
language. Basically, malloc(0) may return null or some arbitrary
pointer, and some implementations will even raise an exception. In any
event, malloc may not be the best analogy for an OO language that had no
type-less pointers. Note that C++ copy constructors require a reference
argument to make it impossible to pass a null pointer.

> I don't believe that this will be a problem for debug as most people
want
> to do a deep copy, and the shallow copy will be at the root of that
deep
> copy, if at all.

I won't argue as to the merits of a deep copy. But, we seem to disagree
on whether this is a debug issue or not. I will only say that if a
subsequent attempt to access the object results in an error, the first
thing the user will try to do is find where the object should have been
created; by making this an error, the tool gives users this information.
If having a null handle is valid then he knows exactly where to change
the code to fix it. 

	Arturo

-----Original Message-----
From: Rich, Dave [mailto:Dave_Rich@mentor.com] 
Sent: Friday, January 19, 2007 11:38 AM
To: Arturo Salz; Steven Sharp; paulsen@cadence.com; sv-ec@eda-stds.org
Subject: RE: [sv-ec] A question about copy constructors

As far as "correctness" is concerned, the current LRM has no
restrictions on what the handle on the RHS of the constructor could be
pointing to, other than in must be assignment compatible to the handle
on the LHS. Null certainly fits within these rules, and the LRM mentions
no need to generate an error. 

So to require an error would not be backwards compatible with the
current LRM.

But I suspect people are more interested in what the *desirable*
behavior should be. If we take an analogy from C, malloc(0) returns a
null pointer and is not an exception case. I don't believe that this
will be a problem for debug as most people want to do a deep copy, and
the shallow copy will be at the root of that deep copy, if at all.

Dave


> -----Original Message-----
> From: owner-sv-ec@server.eda.org [mailto:owner-sv-ec@server.eda.org]
On
> Behalf Of Arturo Salz
> Sent: Friday, January 19, 2007 10:45 AM
> To: Rich, Dave; Steven Sharp; paulsen@cadence.com; sv-ec@server.eda-
> stds.org; Arturo.Salz@synopsys.com
> Subject: RE: [sv-ec] A question about copy constructors
> 
> I'm sorry but Steve is correct. The new method is called the
constructor
> precisely because it creates (i.e., allocates) the object. When
someone
> writes code such as:
> 
> 	p = new q;
> 
> After executing that statement, the expectation is that p will contain
a
> handle to an object that has been created. The term new implies that a
> *newly created* object has been initialized. If the source handle is
> null, you cannot create an object copy so the only reasonable thing is
> to issue an error. As I said before, relaxing the implementation only
> leads to additional debug by users. If having a null object is OK then
> that check should be done by the user prior to calling the copy
> constructor.
> 
> 	Arturo
> 
> -----Original Message-----
> From: Rich, Dave [mailto:Dave_Rich@mentor.com]
> Sent: Thursday, January 18, 2007 5:23 PM
> To: Steven Sharp; paulsen@cadence.com; sv-ec@eda-stds.org;
> Arturo.Salz@synopsys.COM
> Subject: RE: [sv-ec] A question about copy constructors
> 
> A copy of nothing is nothing...
> 
> 'nothing' IS created.
> 
> 
> Nothing from Nothing leaves Nothing....
> http://billypreston.lyrics.info/nothingfromnothing.html
> 
> 
> > -----Original Message-----
> > From: Steven Sharp [mailto:sharp@cadence.com]
> > Sent: Thursday, January 18, 2007 4:21 PM
> > To: sharp@cadence.com; paulsen@cadence.com; sv-ec@eda-stds.org;
> > Arturo.Salz@synopsys.com; Rich, Dave
> > Subject: RE: [sv-ec] A question about copy constructors
> >
> >
> > >But you are making a copy of what the handle points to: nothing.
> >
> > But 'new' creates an object.  If you do not create an object, then
> > you have not performed the primary function of 'new'.  If you do
> > create an object, then that object is not a copy of what the other
> > handle points to.
> >
> > Steven Sharp
> > sharp@cadence.com
> 
> 
> --
> This message has been scanned for viruses and
> dangerous content by MailScanner, and is
> believed to be clean.
> 


-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
Received on Fri Jan 19 12:47:39 2007

This archive was generated by hypermail 2.1.8 : Fri Jan 19 2007 - 12:47:45 PST