Article View: comp.std.c++
Article #3539Re: Is dynamic_cast safe?
From: Tony Cook
Date: Wed, 28 Feb 1996 17:30
Date: Wed, 28 Feb 1996 17:30
33 lines
2011 bytes
2011 bytes
Lars Farm (lars.farm@nts.mh.se) wrote:
: 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?
No, the compiler should produce a diagnostic, see [intro.compliance]
paragraphs 1 through 3.
: ...
: 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?
This one is made pretty clear in the following paragraph:
9 The value of a failed cast to pointer type is the null pointer value
of the required result type. A failed cast to reference type throws
bad_cast (_lib.bad.cast_).
--
Tony Cook - tony@online.tmx.com.au
100237.3425@compuserve.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:
<199602280545.QAA27432@online.tmx.com.au>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: tony@online.tmx.com.au (Tony Cook) Newsgroups: comp.std.c++ Subject: Re: Is dynamic_cast safe? Date: 28 Feb 1996 09:30:38 PST Organization: Home Approved: austern@isolde.mti.sgi.com Message-ID: <199602280545.QAA27432@online.tmx.com.au> References: <AD58B8389668E1A9@sleipner.nts.mh.se> NNTP-Posting-Host: isolde.mti.sgi.com X-Original-Date: Wed, 28 Feb 1996 16:45:15 +1100 X-Newsreader: TIN [version 1.2 PL2] X-Auth: PGPMoose V1.1 PGP comp.std.c++ iQBVAwUBMTSR8ky4NqrwXLNJAQGsLgIAsmBzQXNnq/lb12foO5pCS6VYJkoTjpw7 w6Jd0bfiQPGMCugtptB/4YR0RqGOr+n6APfosGlVH2rEPkUMf8h7LA== =2IVx Originator: austern@isolde.mti.sgi.com