[Issue 5559] A static down cast in Phobos

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Dec 18 11:21:44 PST 2012


http://d.puremagic.com/issues/show_bug.cgi?id=5559



--- Comment #4 from Andrej Mitrovic <andrej.mitrovich at gmail.com> 2012-12-18 11:21:42 PST ---
(In reply to comment #3)
> (In reply to comment #2)
> > I think we should rather add this to the documentation than as a function into
> > Phobos. We don't want to encourage using this but we do want to show it's
> > possible to do it.
> 
> So people that want it write their own possibly buggy version, or copy&paste
> from the documentation their own version, with other possible copying mistakes.

It's unsafe by default no matter if it's in the library or if you copy-paste it
from the documentation. There's no amount of unittests that will help you make
static_cast bug-free and reliable.

Remember that not everyone has a C++ background and they don't necessarily
understand what static_cast is about, they could easily misinterpret this as
just a faster version of a cast, while it's also unsafe.

If people see `static_cast` in code samples (e.g. a dpaste snippet) *that's*
when they'll start copy-pasting code without reading what static_cast does. Or
someone on IRC will say "use static_cast because it's faster", and then people
will wonder why their code segfaults.

We could add a huge bold docstring reading "this is unsafe", but I'm afraid not
everyone reads the documentation.

Anyway try and see what Walter/Andrei think about it, they likely already have
an opinion whether to include this or not.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list