这是Visual C++ 2008的编译器错误吗
Is This a Compiler's Bug of Visual C++ 2008
我正在编写一个简单的模式客户端使用boost asio,但是,当Windows 7(64bit)中的Visual C 2008下的发行模式编译时,该程序将引起访问违规例外无辜的" std :: string s;"在功能处理程序中。欢迎任何建议。
#include <iostream>
#include <boost/asio.hpp>
#include <string>
#include <boost/algorithm/string.hpp>
typedef boost::asio::buffers_iterator<boost::asio::const_buffers_1> iterator_t;
typedef boost::iterator_range<iterator_t> range_t;
static const std::string LINE_END_MARK = "rn";
int main(int argc, char* argv[])
{
boost::asio::streambuf _buf;
std::ostream os(&_buf);
os<<"ENDrn";
iterator_t cursor = boost::asio::buffers_begin(_buf.data());
iterator_t end = boost::asio::buffers_end(_buf.data());
std::ostream_iterator<char> it(std::cout," ");
std::copy(LINE_END_MARK.begin(), LINE_END_MARK.end(), it);
range_t r(cursor, end);
if(!boost::ends_with(r, LINE_END_MARK))
return 0;
return 1;
}
添加"无辜"自动变量时,您正在更改该函数的堆栈框架的布局。发生的事情是,堆栈上的某些变量(始终)损坏会移动。因此,当您以前浪费了一些没有注意到的内存位置时,您现在正在浪费更重要的东西(例如返回地址)。
正如评论中提到的马特球一样,代码中错误的可能性比编译器错误的概率大得多,尤其是在最近的编译器中。如果您仍然确信它是一个编译器错误,则可以通过与另一个编译器(例如GCC或Windows Port,mingw)来确认您的怀疑。
相关文章:
- MSVC多行宏编译器错误
- 静态数据成员的问题-修复链接错误会导致编译器错误
- C++,我收到一个无法理解的编译器错误
- 我收到同义重复编译器错误。我应该如何修复"类型"X"的参数与类型"X"的参数不兼容?
- 重载方法的方式会在使用临时调用时生成编译器错误
- 尝试使用继承和模板实现CRTP.Visual Studio正在生成编译器错误
- 编译器错误:destuctor 的更宽松的抛出说明符
- Android NDK clang 编译器错误在 Windows 上显示'No such file or directory'
- C++ G++ 编译器 - 错误:隐式声明的定义
- 这个失败的测试是将零添加到空指针未定义的行为、编译器错误还是其他什么?
- 模板模板参数和模板别名:编译器错误?
- C++ 编译器错误:P1LinkedList.cpp:145:错误:重载的"to_string(int&)"调用不明确
- 在gcc中意外调用了Const重载.编译器错误或兼容性修复程序
- C1001内部编译器错误是由于矢量初始化(如数组)引起的
- 编译器错误(英特尔并行工作室 2019 与 Visual Studio 社区 2019)
- 如何在C++中克服此 C4430 编译器错误?
- 尝试使用 WinBGI 显示文本时出现编译器错误
- 使用typedef'ed返回类型声明友元函数时出现编译器错误
- 如何在类模板的成员函数中正确调用函数对象?正在生成 Visual Studio 编译器错误 C2440
- C++自定义分配器大小参数作为模板参数会引发编译器错误