Log4cxx
  1. Log4cxx
  2. LOGCXX-152

gcc warning about cast from `const void*' to `log4cxx::helpers::Object*' discards qualifiers from pointer target typ

    Details

    • Type: Improvement Improvement
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 0.10.0
    • Fix Version/s: 0.10.0
    • Component/s: None
    • Labels:
      None
    • Environment:
      OS: linux
      gcc: 3.4.4

      Description

      In the template "template<typename T> class ObjectPtrT" in file "include/log4cxx/helpers/objectptr.h"
      the function "template<typename InterfacePtr> void cast(const InterfacePtr& p1)" uses an "unsafe" cast to (T*).
      This triggers a gcc warning because the "const" qualifier gets casted away.

      I tried the following:

      template<typename InterfacePtr> void cast(const InterfacePtr& p1)
      {

      • T* newPtr = 0;
        + const T* newPtr = 0;
        if (p1 != 0) { - newPtr = (T*)p1->cast(T::getStaticClass()); + newPtr = (const T*)p1->cast(T::getStaticClass()); }

        operator=(newPtr);
        }

      This compiles but the unittests fail.

      In a comment to issue LOGCXX-14 another solution is provided:
      https://issues.apache.org/jira/browse/LOGCXX-14#action_12315059

        Activity

        Hide
        hunger added a comment -

        added link to issue LOGCXX-14

        Show
        hunger added a comment - added link to issue LOGCXX-14
        Hide
        hunger added a comment -

        working patch

        Show
        hunger added a comment - working patch
        Hide
        Curt Arnold added a comment -

        Committed rev 467128.

        Show
        Curt Arnold added a comment - Committed rev 467128.

          People

          • Assignee:
            Curt Arnold
            Reporter:
            hunger
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development