Why are (member) function pointers behaving so weirdly in Visual C++?

后端 未结 3 1992
太阳男子
太阳男子 2020-12-14 06:48

I\'ve had a really bizarre problem that I\'ve reduced to the following test case:

#include 
#include 
#include 

str         


        
3条回答
  •  暖寄归人
    2020-12-14 07:21

    C++11 5.3.1 describes what & does; in this instance, it gives you a pointer to the member function in question, and the passage makes no requirement that this pointer must be unique.

    However, 5.10/1 says about ==:

    Two pointers of the same type compare equal if and only if they are both null, both point to the same function, or both represent the same address.

    The question then becomes... are test1 and test2 "the same function"?

    Though the optimizer has collapsed them into a single definition, arguably the two names identify two functions and, as such, this would seem to be an implementation bug.

    (Note, though, that the VS team don't care and consider it "valid enough" to warrant the benefits of the optimisation. That, or they don't realise that it's invalid.)

    I'd stick to using the strings as "handles" for your function pointers.

提交回复
热议问题