Compiling with VS2015:
template <typename Owner, typename C, typename R, typename... Args>
constexpr bool FunctionBelongsTo(R(C::*)(Args...) const)
{
return std::is_same<C, Owner>::value;
}
class C
{
public:
int x;
};
class D
{
public:
int y;
};
class M : public C, public D
{
public:
void f() const {}
};
static_assert(FunctionBelongsTo<M>(&M::f) != true, "TRUE");
The constexpr function gives a weird error:
error C2131: expression did not evaluate to a constant
note: a non-constant (sub-)expression was encountered
This std::is_same expression is most certainly constant.
The strange thing is, this error seems to be invoked in this very specific case where M is multiply inherited. Remove either of the base classes from M and it compiles just fine (ie, it emits the static_assert, as expected), but when M is multiply inherited like this, it decides the expression is not constant.
... what gives? Rookie error?