This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/39415] static_cast used as downcast can silently lose const
- From: "james.dennett at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Fri, 12 Nov 2010 04:10:18 +0000
- Subject: [Bug c++/39415] static_cast used as downcast can silently lose const
- Auto-submitted: auto-generated
- References: <bug-39415-4@http.gcc.gnu.org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39415
James Dennett <james.dennett at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |james.dennett at gmail dot
| |com
--- Comment #5 from James Dennett <james.dennett at gmail dot com> 2010-11-12 04:10:16 UTC ---
Jason Merrill <jason@redhat.com> has given me a heavy hint leading to the
following smaller and much less ugly patch for cp/typeck.c that makes it more
symmetrical with the reference case. This also passes my simple tests.
.../gcc/cp $ svn diff
Index: typeck.c
===================================================================
--- typeck.c (revision 164712)
+++ typeck.c (working copy)
@@ -5999,7 +5999,8 @@
base = lookup_base (TREE_TYPE (type), TREE_TYPE (intype),
c_cast_p ? ba_unique : ba_check,
NULL);
- return build_base_path (MINUS_EXPR, expr, base, /*nonnull=*/false);
+ expr = build_base_path (MINUS_EXPR, expr, base, /*nonnull=*/false);
+ return cp_fold_convert(type, expr);
}
if ((TYPE_PTRMEM_P (type) && TYPE_PTRMEM_P (intype))