Details
-
Bug
-
Resolution: Fixed
-
Not Evaluated
-
5.9.1
-
None
-
AlpineLinux 3.6 (gcc 6.3.0 and gcc 6.4.0, clang 4.0.0)
Current ArchLinux (gcc 7.1.1, clang 4.0.1)
See: https://bugs.alpinelinux.org/issues/7584
-
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;