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

Assignment operator removes const qualifier

    XMLWordPrintableJSON

Details

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

      Attachments

        1. log4cxx-objectptr-234.patch
          0.8 kB
          Jonathan Wakely

        Activity

          People

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

            Dates

              Created:
              Updated:
              Resolved: