You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Visual C++编译Boost TE库时遇内存访问失败问题求助

问题:MSVC编译boost te库示例时出现运行时访问违例

我计划在采用**Visual C++(版本MSVC 19.29.30153.0,遵循C++20标准)**编译的项目中使用boost te库。

我使用了库文档中最简单的erase it示例,代码如下:

struct Drawable {
  void draw(std::ostream &out) const {
    te::call([](auto const &self, auto &out) { self.draw(out); }, *this, out);
  }
};

struct Square {
  void draw(std::ostream &out) const { out << "Square"; }
};

int main() {
  te::poly<Drawable> d = Square{};
  d.draw();
}

这段代码可正常编译,但运行时在te::poly的如下代码处触发读访问违例:

return reinterpret_cast<R (*)(void *, Ts...)>(self.vptr[N - 1])(
      self.ptr(), std::forward<Ts>(args)...);

报错信息:

Exception thrown: read access violation.
self was 0xFFFFFFFFFFFFFFFF.

我添加变量观察代码:

auto my_pointer = self.ptr();

调用该代码时同样失败,查看变量发现vtable指针已损坏:

self    {vptr=0x00007ff6698614e2 {check_te_windows.exe! ...
+       __vfptr 0x00000142775a64a0 {0x000000fdfdfdfdcd} void * *
+       vptr    0x00007ff6698614e2 

该库在Clang、GCC和Intel OneAPI编译器下均可正常运行。请问Visual C++编译器下出现此问题的原因是什么?


内容的提问来源于stack exchange,提问作者Fantastic Mr Fox

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.29 14:31:04