I've had a really bizarre problem that I've reduced to the following test case:
#include <iostream> #include <map> #include <string> struct Test { std::map<std::string, void (Test::*)()> m; Test() { this->m["test1"] = &Test::test1; this->m["test2"] = &Test::test2; } void test1() { } void test2() { } void dispatch(std::string s) { if (this->m.at(s) == &Test::test1) { std::cout << "test1 will be called..." << std::endl; } else if (this->m.at(s) == &Test::test2) { std::cout << "test2 will be called..." << std::endl; } (this->*this->m.at(s))(); } }; int main() { Test t; t.dispatch("test1"); t.dispatch("test2"); } It outputs
test1 will be called...
test1 will be called...
when optimizations are enabled, which is really bizarre. What's going on?
php,javaandmysqltoo to get everyone involved! =)