boost::bind 违反了严格别名规则?

发布于 2024-09-05 11:48:53 字数 289 浏览 1 评论 0原文

使用Boost 1.43和GCC 4.4.3,以下代码

boost::bind(&SomeObject::memberFunc, this, _1));

生成以下警告

boost/function/function_base.hpp:321: 警告:取消引用类型双关语 指针将破坏严格别名 规则

在不设置 -fno-strict-aliasing 的情况下消除这些警告的正确方法是什么?

Using Boost 1.43 and GCC 4.4.3, the following code

boost::bind(&SomeObject::memberFunc, this, _1));

Generates the following warning

boost/function/function_base.hpp:321:
warning: dereferencing type-punned
pointer will break strict-aliasing
rules

What's the correct way to eliminate these warnings without setting -fno-strict-aliasing?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

π浅易 2024-09-12 11:48:53

仅供记录,我对使用 GCC 4.4.3 的 Google Native Client 的 boost::bind 也有同样的警告。 boost从1.41.0版本升级到1.47.0后,该警告消失了。

Just for the record I had the same warning for boost::bind using GCC 4.4.3 for Google's Native Client. The warning disappeared after upgrading boost from version 1.41.0 to 1.47.0.

魔法少女 2024-09-12 11:48:53

您确定您拥有与成员函数 foo 所在的类相匹配的正确对象吗?换句话说,在你发布的代码中,*this 的类型与 SomeObject 相同吗?当编译器必须跟踪指向相同原始数据的多个不同类型的指针时,就会发生别名,这就是为什么我怀疑 *this 和 SomeObject 的类型不相同的原因。

Are you sure that you've got the right object matched with the class that the member function foo is in? In other words, in the code you posted, is the type of *this the same as SomeObject? Aliasing occurs when the compiler has to track multiple pointers of different types to the same raw data, which is why I suspect that the type of *this and SomeObject are not the same.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文