Article View: comp.std.c++
Article #3533Re: Is dynamic_cast safe?
From: Steve Clamage
Date: Wed, 28 Feb 1996 01:52
Date: Wed, 28 Feb 1996 01:52
27 lines
1981 bytes
1981 bytes
In article AD58B8389668E1A9@sleipner.nts.mh.se, lars.farm@nts.mh.se (Lars Farm) writes:
> 5.2.6 Dynamic cast [expr.dynamic.cast]
> ...
> 6 Otherwise, v shall be a pointer to or an lvalue of a polymorphic type
> ...
>What should happen when 'v' is not a pointer to or an lvalue of a
>polymorphic type? return 0? crash? throw bad_cast? undefined?
> ...
> 8 The run-time check logically executes like this:
> [...] Otherwise, the run-time check fails.
>If fail means undefined, why not require that it returns 0?
The dynamic_cast has two failure modes, depending on whether the cast is
of pointer or reference type (the only two kinds allowed). The last
paragraph of the section says a failed pointer cast returns the null
pointer, and a failed reference cast throws the bad_cast exception.
The behavior is completely defined
---
Steve Clamage, stephen.clamage@eng.sun.com
---
[ comp.std.c++ is moderated. To submit articles: Try just posting with your
newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]
Technical Details
Message-ID:
<4gvb5a$c3s@engnews1.Eng.Sun.COM>Path:
arc1-ca.pugleaf.net!chronicle.mti.sgi.com!austernReferences:
<AD58B8389668E1A9@sleipner.nts.mh.se>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!chronicle.mti.sgi.com!austern From: clamage@Eng.Sun.COM (Steve Clamage) Newsgroups: comp.std.c++ Subject: Re: Is dynamic_cast safe? Date: 27 Feb 1996 17:52:27 PST Organization: Sun Microsystems Inc. Approved: austern@isolde.mti.sgi.com Message-ID: <4gvb5a$c3s@engnews1.Eng.Sun.COM> References: <AD58B8389668E1A9@sleipner.nts.mh.se> Reply-To: clamage@Eng.Sun.COM NNTP-Posting-Host: isolde.mti.sgi.com X-Original-Date: 27 Feb 1996 16:23:06 GMT X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBVAwUBMTO1gUy4NqrwXLNJAQGEZwIAnr9OwLMhm/D25Rz2n6LwECkI+D4gyBgd q3kr8VseMnoJHyduqFmJCz4Y4e1V+571m+w9tCDscRWZDcD5pG8sLQ== =UBXN Originator: austern@isolde.mti.sgi.com