3

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?

Kyle
  • 4,487
  • 3
  • 29
  • 45
  • Boost is not intended or designed to produce no warnings on all compilers. In all probability this is a side effect of using boost::bind. Performance gain of -fno-strict-aliasing is minuscule anyways. – Billy ONeal Jun 15 '10 at 02:28

2 Answers2

2

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.

Sigmund
  • 137
  • 1
  • 5
0

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.

sashang
  • 11,704
  • 6
  • 44
  • 58
  • you are the only answer.. congratulations, you win. (the types of *this and SomeObject are the same though.) – Kyle Jun 19 '10 at 22:54
  • 2
    @Kyle ...That's not how accepting an answer works. Especially when (A) this answer probably should just have been a comment, (B) it overlooks the fact that `bind` almost certainly uses `template` argument matching to require compatible (aliasable) pointer-to-method and pointer-to-instance arguments anyway, meaning the problem would be a bug in the internals of the function, and (C) you openly admit it doesn't solve the problem posed in your question. So don't mark it as the answer! The other answer here _does_ explain it. – underscore_d Aug 27 '16 at 18:50