You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The existing (Safe)MatcherCast and WhenDynamicCastTo do not work well for pointers such as void*, since the former requires the underlying types to be convertible (void => T) and the second simply does not allow void* as the argument.
This is especially needed when mocking APIs which type-erase their arguments as void*, e.g. something like int api(enum message_type type, void* arg).
I was perfectly able to get the expected behavior by simply duplicating all of WhenDynamicCastTo with its underlying implementation and just switching dynamic_cast to static_cast with the corresponding message. Real implementation should probably avoid such duplication and instead just abstract away the casting into something like:
structstatic_caster {
staticconstexprconstchar* name = "static";
template <typename To, typename From>
To cast(From* from) { returnstatic_cast<To>(from); }
// plus overload references
};
// same for dynamic
Other types of casts such as reinterpret, const and C++20 bit should also be considered.
Is the feature specific to an operating system, compiler, or build system version?
No
The text was updated successfully, but these errors were encountered:
Does the feature exist in the most recent commit?
No
Why do we need this feature?
The existing
(Safe)MatcherCast
andWhenDynamicCastTo
do not work well for pointers such asvoid*
, since the former requires the underlying types to be convertible (void => T
) and the second simply does not allowvoid*
as the argument.This is especially needed when mocking APIs which type-erase their arguments as
void*
, e.g. something likeint api(enum message_type type, void* arg)
.Example usage:
Describe the proposal.
I was perfectly able to get the expected behavior by simply duplicating all of
WhenDynamicCastTo
with its underlying implementation and just switchingdynamic_cast
tostatic_cast
with the corresponding message. Real implementation should probably avoid such duplication and instead just abstract away the casting into something like:Other types of casts such as reinterpret, const and C++20 bit should also be considered.
Is the feature specific to an operating system, compiler, or build system version?
No
The text was updated successfully, but these errors were encountered: