Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-77641

Clang Analyzer: d may be uninitialized in QSharedPointer::deref

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • Not Evaluated
    • None
    • 5.12.4
    • None

    Description

      The following example code:

      #include <QSharedPointer>
      
      QPair<int, QSharedPointer<int>> foo() {
      	return {42, nullptr};
      }
      
      int main() {
      	auto [x, p] = foo();
      	auto p2 = p;
      }
      

      Produces the following warning in Clang's Analyzer:

      QtCore.framework/Headers/qsharedpointer_impl.h:460:7: warning: 1st function call argument is an uninitialized value [clang-analyzer-core.CallAndMessage]
          { deref(d); }
            ^
      test.cpp:9:12: note: Uninitialized value stored to '.second.d'
              auto p2 = p;
                        ^
      test.cpp:10:1: note: Calling implicit destructor for 'QPair<int, QSharedPointer<int>>'
      }
      ^
      test.cpp:10:1: note: Calling '~QSharedPointer'
      QtCore.framework/Headers/qsharedpointer_impl.h:315:25: note: Calling 'QSharedPointer::deref'
          ~QSharedPointer() { deref(); }
                              ^
      QtCore.framework/Headers/qsharedpointer_impl.h:460:7: note: 1st function call argument is an uninitialized value
          { deref(d); }
            ^
      

      I'm not really sure what is going on here. Using const auto& in the structured binding or replacing QSharedPointer with std::shared_ptr fixes the warning though.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            thiago Thiago Macieira
            jhasse Jan Niklas Hasse
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes