From -3112594996259848240
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,bed6baff9e441d5c,start
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 2003-02-02 12:23:56 PST
Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!kibo.news.demon.net!mutlu.news.demon.net!demon!mail2news.demon.co.uk!devnull
From: dlagno@mail.nnov.ru (Denis Lagno)
Newsgroups: comp.std.c++
Subject: proposal: "virtual restrict" inheritance
Date: Sun, 2 Feb 2003 20:23:52 +0000 (UTC)
Organization: http://groups.google.com/
Lines: 64
Approved: fjh@cs.mu.oz.au (Fergus Henderson , moderator of comp.std.c++)
Message-ID: <5a0f3464.0302020455.25d887a9@posting.google.com>
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
X-Trace: mail2news.demon.co.uk 1044217432 1006 10.0.0.1 (2 Feb 2003 20:23:52 GMT)
X-Complaints-To: abuse@demon.net
NNTP-Posting-Date: Sun, 2 Feb 2003 20:23:52 +0000 (UTC)
X-Received: from mulga.cs.mu.oz.au ([128.250.1.22])
	by news.demon.co.uk with esmtp (Exim 4.05)
	id 18fQec-0000G4-00
	for mail2news@news.news.demon.net; Sun, 02 Feb 2003 20:23:51 +0000
X-Received: from localhost (localhost [[UNIX: localhost]]) by mulga.cs.mu.OZ.AU
	id HAA28665; Mon, 3 Feb 2003 07:23:47 +1100 (EST)
X-Authentication-Warning: mulga.cs.mu.OZ.AU: fjh set sender to devnull@stump.algebra.com using -f
X-Path: comp-std-cpp-robomod!not-for-mail
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
X-Delivered-To: std-c++@ncar.ucar.edu
X-Newsgroups: comp.std.c++
X-NNTP-Posting-Date: 2 Feb 2003 12:55:09 GMT
X-Spam-Status: No, hits=-2.7 required=5.0
	tests=NOSPAM_INC,SPAM_PHRASE_03_05
	version=2.41
Xref: archiver1.google.com comp.std.c++:17733

[Problem description]
Imagine that you have typical rhomb shaped inheritance framework

     B
   /   \
   C   D
   \   /
     X

If compiler knows that nothing is grafted badly to this structure in
other translation units, it can implement one of inheritances
C:virtual B or D:virtual B not as it usually does -- thru pointer and
indirect access but directly thru statically known offset.

But since compiler sees only one translation unit at a time it cannot
do such optimization.

[Proposed solution]
add "virtual restrict" inheritance.
Now standard says

# For an object of class AA, all virtual occurrences
# of base class B in the class lattice of AA correspond
# to a single B subobject within the object of type AA,
# and every other occurrence of a (non-virtual) base
# class B in the class lattice of AA corresponds
# one-to-one with a distinct B subobject within
# the object of type AA. 

"virtual restrict" inheritance logically shall be the same as usual
"virtual" but with one restriction -- if for any derived class some
base class occurs more than 1 time as "virtual restrict" then the
program is ill-formed.

So changes to standard required are very small and local and without
possible interference with other language features -- because
semantically "virtual restrict" shall everywhere act as usual
"virtual".  But beforementioned restriction enables compiler to
optimize virtual inheritance.

I assumed that keyword "restrict" already included in C99 so it is
good to reuse it in another sense in another place.

[example]
former inheritance framework may be now written as:

class B { ... };

class C: public virtual B { ... };

class D: public virtual restrict B { ... };

class X: public C, public D { ... };

I'll be glad to hear comments.
--
Denis

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]



