Log4cxx
  1. Log4cxx
  2. LOGCXX-234

Assignment operator removes const qualifier

    Details

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

      Description

      This overloaded assignment operator is not const-correct:
      ObjectPtrT& ObjectPtrT::operator=(const T* p1);
      This allows:
      typedef const Foo CFoo;
      CFoo* p = new CFoo(some_foo);
      ObjectPtrT<Foo> op;
      op = p;
      *op = another_foo;
      assert( *p == some_foo ); // boom!

      If there are cases where the const-ness needs to be removed, it should
      be done explicitly by the user of ObjectPtrT, since only the user
      knows if a particular case is safe or not. Doing it automatically
      inside ObjectPtrT hides potentially serious errors.
      I removed that assignment operator and successfully built and tested
      the lib with make check, so I conclude it's not needed anyway.

      If you do need to store a pointer-to-const in an ObjectPtrT you can do:
      ObjectPtrT<const Foo> op;
      op = p;

        Activity

        No work has yet been logged on this issue.

          People

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

            Dates

            • Created:
              Updated:
              Resolved:

              Development