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

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

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 0.10.0
    • None
    • Build
    • 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.

      Attachments

        Activity

          People

            carnold@apache.org Curt Arnold
            miielz Myles Bunbury
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: