This crash occurs in Centos 7.4 and Centos 6.9 w/ devtoolkit-6. In other words, GCC 6 plus intel compiler 2018.1. There is no crash using 2018.0. It works fine in -O0 but -O2 and -O3 crash.
#include <cstring>
#include <string>
#include <iostream>
std::string a() {
return "xxxxxxxxxxxxxxxxxx";
}
std::string b() {
return std::string("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") + std::string("x");
}
int main( int argc, char *argv[] ) {
auto s = a() + b();
printf("%s, %lu, %lu\n", s.c_str(), s.length(), strlen(s.c_str()));
return 0;
}