public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/39415]  New: static_cast used as downcast can silently lose const
@ 2009-03-09 20:03 algrant at acm dot org
  2009-03-10 11:04 ` [Bug c++/39415] " rguenth at gcc dot gnu dot org
                   ` (3 more replies)
  0 siblings, 4 replies; 8+ messages in thread
From: algrant at acm dot org @ 2009-03-09 20:03 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/39415] static_cast used as downcast can silently lose const
  2009-03-09 20:03 [Bug c++/39415] New: static_cast used as downcast can silently lose const algrant at acm dot org
@ 2009-03-10 11:04 ` rguenth at gcc dot gnu dot org
  2010-07-18 21:40 ` james dot dennett at gmail dot com
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-03-10 11:04 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from rguenth at gcc dot gnu dot org  2009-03-10 11:04 -------
Confirmed.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
           Keywords|                            |accepts-invalid
   Last reconfirmed|0000-00-00 00:00:00         |2009-03-10 11:04:47
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39415


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/39415] static_cast used as downcast can silently lose const
  2009-03-09 20:03 [Bug c++/39415] New: static_cast used as downcast can silently lose const algrant at acm dot org
  2009-03-10 11:04 ` [Bug c++/39415] " rguenth at gcc dot gnu dot org
@ 2010-07-18 21:40 ` james dot dennett at gmail dot com
  2010-07-18 22:11 ` redi at gcc dot gnu dot org
  2010-07-18 22:13 ` redi at gcc dot gnu dot org
  3 siblings, 0 replies; 8+ messages in thread
From: james dot dennett at gmail dot com @ 2010-07-18 21:40 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from james dot dennett at gmail dot com  2010-07-18 21:39 -------
44916 is a duplicate of this bug (and includes a hacky fix, but no automated
regression test).


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39415


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/39415] static_cast used as downcast can silently lose const
  2009-03-09 20:03 [Bug c++/39415] New: static_cast used as downcast can silently lose const algrant at acm dot org
  2009-03-10 11:04 ` [Bug c++/39415] " rguenth at gcc dot gnu dot org
  2010-07-18 21:40 ` james dot dennett at gmail dot com
@ 2010-07-18 22:11 ` redi at gcc dot gnu dot org
  2010-07-18 22:13 ` redi at gcc dot gnu dot org
  3 siblings, 0 replies; 8+ messages in thread
From: redi at gcc dot gnu dot org @ 2010-07-18 22:11 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from redi at gcc dot gnu dot org  2010-07-18 22:11 -------
*** Bug 44916 has been marked as a duplicate of this bug. ***


-- 

redi at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ian at airs dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39415


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/39415] static_cast used as downcast can silently lose const
  2009-03-09 20:03 [Bug c++/39415] New: static_cast used as downcast can silently lose const algrant at acm dot org
                   ` (2 preceding siblings ...)
  2010-07-18 22:11 ` redi at gcc dot gnu dot org
@ 2010-07-18 22:13 ` redi at gcc dot gnu dot org
  3 siblings, 0 replies; 8+ messages in thread
From: redi at gcc dot gnu dot org @ 2010-07-18 22:13 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from redi at gcc dot gnu dot org  2010-07-18 22:13 -------
Adding wrong-code keyword, as shown by the testcase in PR 44916


-- 

redi at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |wrong-code
      Known to fail|                            |4.4.4 4.5.1 4.6.0
   Last reconfirmed|2009-03-10 11:04:47         |2010-07-18 22:13:44
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39415


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/39415] static_cast used as downcast can silently lose const
       [not found] <bug-39415-4@http.gcc.gnu.org/bugzilla/>
  2010-11-12  4:10 ` james.dennett at gmail dot com
  2010-11-12 18:19 ` jason at gcc dot gnu.org
@ 2011-06-10 17:29 ` paolo.carlini at oracle dot com
  2 siblings, 0 replies; 8+ messages in thread
From: paolo.carlini at oracle dot com @ 2011-06-10 17:29 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39415

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |FIXED
   Target Milestone|---                         |4.6.0
      Known to fail|                            |

--- Comment #7 from Paolo Carlini <paolo.carlini at oracle dot com> 2011-06-10 17:28:51 UTC ---
Fixed in 4.6.0.


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/39415] static_cast used as downcast can silently lose const
       [not found] <bug-39415-4@http.gcc.gnu.org/bugzilla/>
  2010-11-12  4:10 ` james.dennett at gmail dot com
@ 2010-11-12 18:19 ` jason at gcc dot gnu.org
  2011-06-10 17:29 ` paolo.carlini at oracle dot com
  2 siblings, 0 replies; 8+ messages in thread
From: jason at gcc dot gnu.org @ 2010-11-12 18:19 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=39415

--- Comment #6 from Jason Merrill <jason at gcc dot gnu.org> 2010-11-12 18:00:25 UTC ---
Author: jason
Date: Fri Nov 12 18:00:21 2010
New Revision: 166667

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=166667
Log:
    PR c++/39415
    * typeck.c (build_static_cast_1): Convert to the target type
    when doing static_cast<cv Derived*>(Base*).

Added:
    trunk/gcc/testsuite/g++.dg/expr/static_cast7.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/typeck.c
    trunk/gcc/testsuite/ChangeLog


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [Bug c++/39415] static_cast used as downcast can silently lose const
       [not found] <bug-39415-4@http.gcc.gnu.org/bugzilla/>
@ 2010-11-12  4:10 ` james.dennett at gmail dot com
  2010-11-12 18:19 ` jason at gcc dot gnu.org
  2011-06-10 17:29 ` paolo.carlini at oracle dot com
  2 siblings, 0 replies; 8+ messages in thread
From: james.dennett at gmail dot com @ 2010-11-12  4:10 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2011-06-10 17:29 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-03-09 20:03 [Bug c++/39415] New: static_cast used as downcast can silently lose const algrant at acm dot org
2009-03-10 11:04 ` [Bug c++/39415] " rguenth at gcc dot gnu dot org
2010-07-18 21:40 ` james dot dennett at gmail dot com
2010-07-18 22:11 ` redi at gcc dot gnu dot org
2010-07-18 22:13 ` redi at gcc dot gnu dot org
     [not found] <bug-39415-4@http.gcc.gnu.org/bugzilla/>
2010-11-12  4:10 ` james.dennett at gmail dot com
2010-11-12 18:19 ` jason at gcc dot gnu.org
2011-06-10 17:29 ` paolo.carlini at oracle dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).