Log4cxx
  1. Log4cxx
  2. LOGCXX-183

Compiler warning: dereferencing type-punned pointer will break strict-aliasing rules

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 0.10.0
    • Fix Version/s: None
    • Component/s: Build
    • Labels:
      None

      Description

      The following line of code:
      void* oldPtr = ObjectPtrBase::exchange((volatile void**) &this->p, newPtr);
      in the ObjectPtrT template class (objectptr.h) produces a 'dereferencing type-punned pointer will break strict aliasing rules' compiler warning.

      This line can be found (with slight variances) in the destructor, operator=(const int& null), operator=(T* p1), and operator=(const ObjectPtrT& p1) functions.

      This warning was produced with gcc v4.1.1 using the following compiler options:
      -Wall -Wextra -Wno-unused-parameter -O3 -mtune-i686

      After investigating, the warning is being caused by the first parameter.

      Replacing all instances of the aforementioned code with the following makes the warning disappear:
      T** pp = &this->p;
      void* oldPtr = ObjectPtrBase::exchange((volatile void**) pp, newPtr);

      A temporary workaround is to use the '-fno-strict-aliasing' compiler option.

        Activity

        No work has yet been logged on this issue.

          People

          • Assignee:
            Curt Arnold
            Reporter:
            Myles Bunbury
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development