Details
-
Bug
-
Resolution: Done
-
P2: Important
-
None
-
5.11.1
-
None
Description
(As reported on StackOverflow.)
The following code produces an unexpected output when compiled with g++ main.cpp -O3 -std=c++17 -Wall -fPIC -I/usr/include/qt -I/usr/include/qt/QtCore -lQt5Core (GCC version 8.1.1, Qt version 5.11.1, Arch Linux).
#include <QString> #include <QDebug> #include <vector> #include <tuple> int main() { typedef std::pair<QString,int*> A; std::vector<A> v; v.emplace_back("111", nullptr); v.emplace_back("222", nullptr); v.emplace_back("333", nullptr); v.emplace_back("444", nullptr); v.emplace_back("555", nullptr); for (const A &a : v) qDebug() << a.first; return 0; }
The output is as follows.
"" "" "" "" "555"
It seems like the vector resize triggers some problem with the move constructor.
Adding the -fno-strict-aliasing compiler option circumvents the problem. (According to the GCC web page, this is a hint that it's a bug in the code, not in GCC.)