Uploaded image for project: 'Log4cxx'
  1. Log4cxx
  2. LOGCXX-152

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

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Resolved
    • Minor
    • Resolution: Fixed
    • 0.10.0
    • 0.10.0
    • None
    • None
    • 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

      Attachments

        1. gcc_warning.patch
          0.5 kB
          hunger

        Activity

          People

            carnold@apache.org Curt Arnold
            hunger hunger
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: