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] New: static_cast used as downcast can silently lose const


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


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