Quantcast
Channel: Visual Studio General Questions forum
Viewing all articles
Browse latest Browse all 21115

A bug in MSVC 2013

$
0
0

Hi there.

I was trying out 2013 because of these new nice C++ features from new standart and that's what I found..

I experienced a nasty deadlock and I wasn't able to find a reason for quite some time..

It realy looks like in this case compiler does not call a destructor for a temporary variable, so it doesn't delete itself from debug iterator list in vector container. I made as small test as possible to make this problem to reproduce.

Problem exists only in Debug.

In example code you can comment "#define I_WANT_A_DEAD_LOCK" line to make code work. You can see that only this it make is writes

autotmpIt = (it + 5);

v2.push_back (SumeNumbersWithOneMoreDoulbe {*numIt, *tmpIt});

instead of just

v2.push_back (SumeNumbersWithOneMoreDoulbe {*numIt, *(it + 5)});

it makes compiler to call destructor for tmpIt...

whole code is

#include <vector>
#include <iostream>

#include <conio.h>

struct SomeNumbers
{
 std::vector<double> doubles_;
};

struct SumeNumbersWithOneMoreDoulbe
{
 SomeNumbers numbers_;
 double d;
};

#define I_WANT_A_DEAD_LOCK

int main ()
{
 std::vector<double> v1;
 std::vector<SomeNumbers> numbers;
 std::vector<SumeNumbersWithOneMoreDoulbe> v2;

 v1.resize (100);
 numbers.resize (10);

 auto numIt = numbers.begin ();

#ifdef I_WANT_A_DEAD_LOCK
 for (auto it = v1.begin (), itEnd = v1.end (); it != itEnd; it += 10, ++numIt)
 {
  v2.push_back (SumeNumbersWithOneMoreDoulbe {*numIt, *(it + 5)});
 }
#else
 for (auto it = v1.begin (), itEnd = v1.end (); it != itEnd; it += 10, ++numIt)
 {
  auto tmpIt = (it + 5);
  v2.push_back (SumeNumbersWithOneMoreDoulbe {*numIt, *tmpIt});
 }
#endif

 std::cout << "done";
 _getch ();
}


Viewing all articles
Browse latest Browse all 21115

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>