Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Crash when initializing vector with one element using brace initialization in VS2019

Tags:

c++

The following code crashes deep inside the standard library:

#include <set>
#include <vector>

struct Parent
{
    std::set<int> v;
};

struct Child : public Parent
{
    Child() = default;
};

int main()
{
    std::vector<Child> v{ {} };
}

but if the constructor is explicitly declared (without = default), it doesn't crash. I don't understand why. I'm using VS2019.

like image 578
Michael Avatar asked Nov 05 '20 20:11

Michael


1 Answers

I looked up into the code and it really caused to happen in Visual Studio 16.7.7. Now it seems to be working fine in both in VS 16.8.3 and g++ (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0 (tried with -std=c++14), it was a bug which seems to be fixed by Microsoft team in the recent update.

like image 108
Rohan Bari Avatar answered Nov 12 '22 18:11

Rohan Bari