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

QVersionNumber seems broken on -O1 and higher with g++

    XMLWordPrintable

Details

    • 77923604130057261bf774b5cc32d849a595a1f0 4f785cc950 (qt/qtbase/6.2) 4f785cc950 (qt/tqtc-qtbase/6.2) 3769340f3c (qt/tqtc-qtbase/5.15) 6afd877d3b (qt/qtbase/6.3) 6afd877d3b (qt/tqtc-qtbase/6.3)

    Description

      If we use QVersionNumber and enable compile optimization the initial usage of idx is not correct.

      #include <QVersionNumber>
      #include <QDebug>
      
      int main(int argc, char** argv)
      {
              const QString pVersion = QStringLiteral("1.12.2");
              int idx = 0;
              const auto& version = QVersionNumber::fromString(pVersion, &idx);
              if(idx == 0)
                      qDebug() << "broken";
              else
                      qDebug() << "ok";
      
              qDebug() << "idx:" << idx;
              return 0;
      }
      

      g++ with -O0

      $ g++ main.cpp -std=c+11 -fPIC `pkg-config --libs --cflags Qt5Core` -lstdc+ -O0
      $ ./a.out
      ok
      idx: 6

      g++ with -O2

      $ g++ main.cpp -std=c+11 -fPIC `pkg-config --libs --cflags Qt5Core` -lstdc+ -O2
      $ ./a.out
      broken
      idx: 6

      clang++ with -O2

      $ clang++ main.cpp -std=c+11 -fPIC `pkg-config --libs --cflags Qt5Core` -lstdc+ -O2
      $ ./a.out
      ok
      idx: 6

      If we do not initialize idx to 0, it will work.

              int idx;
      

      Attachments

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

        Activity

          People

            thiago Thiago Macieira
            misery André Klitzing
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: