 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
kanze@gabi-soft.fr Guest
|
Posted: Sat Jul 12, 2003 8:00 am Post subject: Defect report [basic.life], cannot call base class functions |
|
|
Richard Smith <richard (AT) ex-parrot (DOT) com> wrote
[I've cross posted to comp.std.c++, because IMHO, this is a standards
problem, probably a defect. I'd set follow-ups as well, but I'm posting
through Google, which doesn't allow it.]
| Quote: | Nonsense. You can use "this" perfectly happily in a constructor, just
be careful that (a) you're not using any members that are not fully
initialised, and (b) if you're calling virtual functions you know
exactly what you're doing.
|
In practice, and I think in intent, you are right. However, the
standard makes some pretty stringent restrictions in 3.8. To start
with, it says (in paragraph 1):
The lifetime of an object is a runtime property of the object. The
lifetime of an object of type T begins when:
-- storage with the proper alignment and size for type T is
obtained, and
-- if T is a class type with a non-trivial constructor, the
constructor calls has COMPLETED.
The lifetime of an object of type T ends when:
-- if T is a class type with a non-trivial destructor, the
destructor call STARTS, or
-- the storage which the object occupies is reused or released.
(Emphisis added.) Then when we get down to paragraph 5, it says:
Before the lifetime of an object has started but after the storage
which the object will occupy has been allocated [which sounds to me
like it would include in the constructor, given the text above] or,
after the lifetime of an object has ended and before the storage
which the object occupied is reused or released, any pointer that
refers to the storage location where the object will be or was
located may be used but only in limited ways. [...] If the object
will be or was of a non-POD class type, the program has undefined
behavior if:
[...]
-- the pointer is implicitly converted to a pointer to a base class
type, or [...]
I can't find any exceptions for the this pointer.
Note that calling a non-static function in the base class, or even
constructing the base class in initializer list, involves an implicit
conversion of this to a pointer to the base class. Thus undefined
behavior. I'm sure that this wasn't the intent, but it would seem to be
what this paragraph is saying.
--
James Kanze GABI Software mailto:kanze (AT) gabi-soft (DOT) fr
Conseils en informatique orientée objet/ http://www.gabi-soft.fr
Beratung in objektorientierter Datenverarbeitung
11 rue de Rambouillet, 78460 Chevreuse, France, +33 (0)1 30 23 45 16
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
[ 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 ]
------------ And now a word from our sponsor ---------------------
For a secure high performance FTP using SSL/TLS encryption
upgrade to SurgeFTP
---- See http://netwinsite.com/sponsor/sponsor_surgeftp.htm ----
|
|
| Back to top |
|
 |
Fergus Henderson Guest
|
Posted: Sat Jul 12, 2003 4:10 pm Post subject: Re: Defect report [basic.life], cannot call base class funct |
|
|
[email]kanze (AT) gabi-soft (DOT) fr[/email] writes:
| Quote: | I've cross posted to comp.std.c++, because IMHO, this is a standards
problem, probably a defect.
....
the standard makes some pretty stringent restrictions in 3.8.
....
I can't find any exceptions for the this pointer.
|
The issue is not exceptions for the "this" pointer, rather it is
exceptions for objects which are currently undergoing construction or
destruction. Indeed, there are special rules for those, which are
described in section 12.7 [class.cdtor]. The note in section 3.8
[basic.life] does refer to 12.7, and I'm sure the intent was that 12.7
take precedence over 3.8 for such objects. But the normative wording
in 3.8 doesn't say that. So I agree that this is a defect.
--
Fergus Henderson <fjh (AT) cs (DOT) mu.oz.au> | "I have always known that the pursuit
The University of Melbourne | of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh> | -- the last words of T. S. Garp.
---
[ 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 ]
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|