Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-10664

template ptr<T> class not const correct

    XMLWordPrintableJSON

Details

    • Icon: Improvement Improvement
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • None
    • 2.5.2
    • Internal Code
    • C++ generic

    Description

      I was browsing the mongodb code in doxygen (I'm thinking of "stealing" your ptr<T> class) and noticed that the operator->() and operator*() (dereference) are not const correct:

      T* operator->() const

      { return _p; }
      T& operator*() const { return *_p; }
      operator T* () const { return _p; }

      should be:

      const T* operator->() const

      { return _p; }
      const T& operator*() const { return *_p; }
      operator const T* () const { return _p; }

      // ... and if you want non-const versions.
      T* operator->()

      { return _p; }
      T& operator*() { return *_p; }
      operator T* () { return _p; }

      If there is some rationale for violating the const correctness, it should at least be documented in a comment (didn't notice anything in the doxygen documentation regarding this).

      Attachments

        Activity

          People

            schwerin@mongodb.com Andy Schwerin
            mhcox Michael H. Cox
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: