Created
May 27, 2021 12:29
-
-
Save gjasny/f7881df48661e7c937dabdccc204c080 to your computer and use it in GitHub Desktop.
MSVS miscompile
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <memory> | |
#include <string> | |
#include <functional> | |
#include <type_traits> | |
// 1 parameter | |
template <class IUser, class Param1> class Command_1p { | |
public: | |
typedef void (IUser::* MemberFunctionType)(Param1); | |
Command_1p(MemberFunctionType pMemberFunction, Param1 p1) | |
: m_pMemberFunction(pMemberFunction) | |
, m_param1(p1) | |
{ | |
} | |
void callUserImpl(IUser* pUserImpl) const | |
{ | |
(pUserImpl->*m_pMemberFunction)(m_param1); | |
} | |
private: | |
MemberFunctionType m_pMemberFunction; | |
typename std::remove_reference<Param1>::type m_param1; | |
}; | |
template <class callee, class param1> | |
std::shared_ptr<Command_1p<callee, param1>> | |
makeCommand(void (callee::* pmf)(param1), typename std::remove_reference<param1>::type p1) | |
{ | |
Command_1p<callee, param1>* pC = new Command_1p<callee, param1>(pmf, p1); | |
return std::shared_ptr<Command_1p<callee, param1>>(pC); | |
} | |
class IProxygenDefaultBase | |
{ | |
public: | |
virtual ~IProxygenDefaultBase() = default; | |
virtual void methOverloadInherited(int delay) = 0; | |
}; | |
class IOtherInterface | |
{ | |
public: | |
virtual ~IOtherInterface() = default; | |
}; | |
class IProxygenDefault : public IProxygenDefaultBase, public IOtherInterface | |
{ | |
public: | |
virtual ~IProxygenDefault() = default; | |
using IProxygenDefaultBase::methOverloadInherited; | |
virtual void methOverloadInherited(const std::string& delay) = 0; | |
}; | |
class MyProxygenDefault : public IProxygenDefault | |
{ | |
public: | |
void methOverloadInherited(const std::string& delay) override {} | |
void methOverloadInherited(int delay) override {} | |
}; | |
int main() | |
{ | |
auto foo = makeCommand<IProxygenDefault, int>(&IProxygenDefault::methOverloadInherited, 33); | |
MyProxygenDefault my; | |
foo->callUserImpl(&my); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment