jeudi 5 mai 2016

Crash in VS2013 SP5 when inserting initializer_list into vector

Seeing a crash with the below code. I know initialize_lists have a poor reputation in VS, but I thought most of them were fixed with 2013 sp3. The same code works fine in g++ (6.1). Am I missing something here? This seems far too simple.

The debugger suggests a problem with an invalid iterator in the xstring module. The same code works find with integers, so I'm guessing it relates to some sort of string specific optimization.

#include <vector>
#include <iostream>
#include <string>

int main(int argc, char** argv)
{
    std::vector<std::string> x = {"a","b","c","d"};

    for(auto i : x)
        std::cout << i << ":";
    std::cout << std::endl;

    x.insert(x.end(), {"e","f"});  // Crash here

    for(auto i : x)
        std::cout << i << ":";
    std::cout << std::endl;

    return 0;
}

Aucun commentaire:

Enregistrer un commentaire