We are migrating issue tracker of Cocos2d-x Project to Github, please create new issue there. Thanks.
Not standard conformant casting of member function pointers (selectors)
Not standard conformant casting of member function pointers (selectors)
Bug #3555 [Closed]
Redmine issue system is closed, we are using github issue system instead.
This issue was moved to https://github.com/cocos2d/cocos2d-x/issues/8292
Status: | Closed | |
---|---|---|
Start date: | 2013-12-31 | |
Priority: | Low | |
Due date: | ||
Assignee: | - | |
% Done: | 0% |
|
Category: | all, windows, wp8 | |
Target version: | - | |
Estimated time: | 0.50 point |
Cocos2d-x 2.x uses not standard conformant C-style casting for member function pointers.
Consider following code from CCObject.h:
typedef void (CCObject::*SEL_CallFuncN)(CCNode*);
#define callfuncN_selector(_SELECTOR) (SEL_CallFuncN)(&_SELECTOR)The C-style cast is used to cast between pointers to member functions.
C-style casts use following casts:
# const_cast
# static_cast
# static_cast followed by const_cast
# reinterpret_cast
# reinterpret_cast followed by const_cast
The key-part of this bug report is what the standard says about performing casts on member function pointers: http://www.open-std.org/jtc1/sc22/WG21/docs/wp/html/nov97-2/conv.html\#conv.mem
Casting with C-style cast will finally result with reinterpet_cast, that leads directly to UB. Moreover, they allow you to cast even between pointer to methods of different signatures without a warning.
The situation is even more complicated on Visual C++ compiler that can generate wrong code due to different pointer to member representation. Despite of using static_cast you’ll often get warning C4407 (http://msdn.microsoft.com/en-us/library/1s6193tt.aspx) when casting objects with multiple inheritance.
It is caused by incorrect implementation of member function pointer in VC.
http://social.msdn.microsoft.com/Forums/vstudio/en-US/a9cfa5c4-d90b-4c33-89b1-9366e5fbae74/strange-error-while-casting-pointers-to-member-functions?forum=vclanguage
The solution is to add /vmg flag to the compiler.
So the actual bugfix’d be to change C-style cast in all selector to static_cast and add /vmg flag to Visual Studio projects.