Search code examples
c++visual-c++visual-c++-2005visual-c++-2008

ITERATOR LIST CORRUPTED in std::string constructor


The code below compiled in Debug configuration in VS2005 SP1 shows two messages with “ITERATOR LIST CORRUPTED” notice.

Code Snippet

#define _SECURE_SCL 0
#define _HAS_ITERATOR_DEBUGGING 0

#include <sstream>
#include <string>

int main()
{
  std::stringstream stream;
  stream << "123" << std::endl;
  std::string str = stream.str();
  std::string::const_iterator itFirst = str.begin();
  int position = str.find('2');
  std::string::const_iterator itSecond = itFirst + position;
  std::string tempStr(itFirst,itSecond); ///< errors are here
  return 0;
}

Is it a bug in the compiler or standard library?


Solution

  • What @dirkgently said in his edit.

    Apparently, some code for std::string is located in the runtime dll, in particular the macro definition does not take effect for the constructor an the code for iterator debugging gets executed. You can fix this by linking the runtime library statically.

    I would consider this a bug, though perhaps not in the Visual Studio itself, but in the documentation.