This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/39415] New: static_cast used as downcast can silently lose const
- From: "algrant at acm dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 9 Mar 2009 20:03:19 -0000
- Subject: [Bug c++/39415] New: static_cast used as downcast can silently lose const
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
This is silently accepted:
struct T { };
struct T_impl: public T { };
T_impl *g(T *tp) { return static_cast<const T_impl*>(tp); }
The result type of the static_cast is pointer-to-const and should not
convert to a pointer-to-non-const. This seems to be specific to when
it is used as a downcast. Replacing the last line with
T *g(T *tp) { return static_cast<const T*>(tp); }
is faulted as expected.
--
Summary: static_cast used as downcast can silently lose const
Product: gcc
Version: 4.3.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: algrant at acm dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39415