This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/32525] Request for new warning: useless dynamic_casts
- From: "lloyd at randombit dot net" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 27 Jun 2007 19:06:48 -0000
- Subject: [Bug c++/32525] Request for new warning: useless dynamic_casts
- References: <bug-32525-6477@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #3 from lloyd at randombit dot net 2007-06-27 19:06 -------
"I haven't seen such code written in the first place ever."
Neither had I, until I found out it is endemic in a large project at work.
I'd just as soon write a script to find these cases, but figuring out what the
type of the casted-from pointer/reference is can be somewhat nontrivial.
"Warnings are for cases where either code may not do what you expect, or where
a certain way of coding has a significant cost that can be avoided."
I think that's a good definition. My impression is that dynamic_cast is fairly
expensive, and while it is great that GCC noops out this case I suspect not all
compilers will do the same; at this point I'm not even sure that GCC does it
consistently. So I'd figure it a reasonable case for a warning as per your
second condition.
"I doubt anyone will ever implement this."
I've gotten used to that. :)
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32525