This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/39415] static_cast used as downcast can silently lose const


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))


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]