Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does nested initializer_list cause memory leaks

Recently I've upgraded my project to Visual Studio 2013. Thus initializer_list feature is now available. I need to initialize test data in my unit tests. But I am getting memory leaks using nested initialize_lists.

#include <memory>
#include <boost/test/unit_test.hpp>

struct Test_Fixture
{
    Test_Fixture()
    :test_data({
        std::make_shared<std::vector<int>>(std::vector<int>{ 0, 1 }),
        std::make_shared<std::vector<int>>(std::vector<int>{ 2, 3, 4 })
    }) {}

    std::vector<std::shared_ptr<std::vector<int>>> test_data;
};

BOOST_FIXTURE_TEST_CASE( testcase_1, Test_Fixture )
{
    BOOST_CHECK(true);
}

Output:

1>  Detected memory leaks!
1>  Dumping objects ->
1>  {1593} normal block at 0x0051A6E8, 8 bytes long.
1>   Data: <` C     > 60 F6 43 00 00 00 00 00 
1>  Object dump complete.
like image 647
user3024877 Avatar asked Nov 11 '22 17:11

user3024877


1 Answers

Looks like a compiler bug: See here

This feature doesn't like having classes as list items. See here

like image 85
egur Avatar answered Nov 15 '22 13:11

egur