Thread View: comp.std.c++
4 messages
4 total messages
Started by Lars Farm
Tue, 27 Feb 1996 16:01
Is dynamic_cast safe?
Author: Lars Farm
Date: Tue, 27 Feb 1996 16:01
Date: Tue, 27 Feb 1996 16:01
22 lines
1403 bytes
1403 bytes
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?
--
Lars Farm, lars.farm@nts.mh.se
[ 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
]
Re: Is dynamic_cast safe?
Author: 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
]
Re: Is dynamic_cast safe?
Author: Fergus Henderson
Date: Wed, 28 Feb 1996 14:56
Date: Wed, 28 Feb 1996 14:56
25 lines
1799 bytes
1799 bytes
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?
If `v' is not a pointer to or an lvalue of a polymorphic type, then
the program is ill-formed, and the implementation must issue a diagnostic.
--
Any mail to me between Feb 25th and 27th may have gone to the bit bucket
(#&$^@$!# mail software silently ignored disk full error). Please resend.
(comp.std.c++ articles were not affected, so no need to resend those.)
Fergus Henderson WWW: http://www.cs.mu.oz.au/~fjh
fjh@cs.mu.oz.au PGP: finger fjh@128.250.37.3
---
[ To submit articles: try just posting with your news-reader.
If that fails, use mailto:std-c++@ncar.ucar.edu
FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html
Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu.
]
Re: Is dynamic_cast safe?
Author: 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
]
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads