Article View: comp.std.c++
Article #2638Re: an optimization I claim is illegal
From: Andrew Koenig
Date: Sat, 18 Nov 1995 20:09
Date: Sat, 18 Nov 1995 20:09
47 lines
1757 bytes
1757 bytes
In article <martelli.816557310@cadlab> martelli@cadlab.it (Alex Martelli) writes:
> virtual void Derived::f() {
> cout<<"Derived ";
> if(--n==0) {
> this->~Derived();
> new(this) Base;
> }
> }
> Isn't this a strictly conformant, well-defined program
The work on the object model is not quite complete, but the
direction it is going is towards a `no' answer here.
One reason is this:
class Foo {
public:
virtual void f();
// ...
};
void g() {
Foo foo;
foo.f(); // virtual?
foo.f(); // virtual?
}
It would be nice if each call to foo.f could avoid the run-time
dispatch overhead, because object foo is known to be of type Foo.
But one could imagine that Foo::f, compiled separately, changes
the type of its object to Bar (derived from Foo and known to be
the same size) and Bar::f changes it back to Foo (so the destructor
will do the right thing). The people I've talked to on the committee
agree that such programs should be taken out and shot; therefore
they will not bless such behavior.
--
--Andrew Koenig
ark@research.att.com
---
[ comp.std.c++ is moderated. Submission address: std-c++@ncar.ucar.edu.
Contact address: std-c++-request@ncar.ucar.edu. The moderation policy
is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
Technical Details
Message-ID:
<DI8rMz.H2z@research.att.com>Path:
arc1-ca.pugleaf.net!news.mindlink.net!agate!agate!MattReferences:
<martelli.816557310@cadlab>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!news.mindlink.net!agate!agate!Matt From: ark@research.att.com (Andrew Koenig) Newsgroups: comp.std.c++ Subject: Re: an optimization I claim is illegal Date: 18 Nov 1995 20:09:51 GMT Organization: AT&T Bell Laboratories, Murray Hill NJ Approved: Matt@Austern Message-ID: <DI8rMz.H2z@research.att.com> References: <martelli.816557310@cadlab> NNTP-Posting-Host: austern.hip.berkeley.edu