Uploaded image for project: 'Qt Creator'
  1. Qt Creator
  2. QTCREATORBUG-23181

"Convert to Stack Variable" and "convert to Pointer" generates invalid code

    XMLWordPrintable

Details

    • 1ab9dc946410e96e0e211347e9d9127740ab18dd (qt-creator/qt-creator/4.11)

    Description

      "Convert to Stack Variable" and "convert to Pointer" generates invalid code

      Case 1. (Convert to Stack Variable)
      from: QObject *obj = new QObject(this);
      to: QObject obj = this;
      expected: QObject obj(this);
      
      Case 2. (Convert to Stack Variable)
      from: QObject *obj = new QObject{this};
      to: QObject obj;
      expected: QObject obj{this};
      
      Case 3. (Convert to Stack Variable)
      from: QByteArray *buf = new QByteArray("text", 4);
      to: QByteArray buf = "text", 4;
      expected: QByteArray buf("text", 4);
      
      Case 4. (Convert to Stack Variable)
      from: QByteArray *buf = new QByteArray{"text", 4};
      to: QByteArray buf;
      expected: QByteArray buf{"text", 4};
      
      Case 5. (Convert to Pointer)
      from: QObject obj;
      to: QObject *obj;
      expected: QObject *obj = new QObject;
      
      Case 6. (Convert to Pointer)
      from: QObject obj{this};
      to: QObject *obj{this};
      expected: QObject *obj = new QObject{this};
      

      Even the documentation at https://doc.qt.io/qtcreator/creator-editor-refactoring.html needs to be updated as it is not in sync with current behaviour.

      Attachments

        For Gerrit Dashboard: QTCREATORBUG-23181
        # Subject Branch Project Status CR V

        Activity

          People

            davschul David Schulz
            shmittal Shveta Mittal
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes