To avoid complexity, below is a minimal example. For some reason, I have to pass normal object as const
to some method and use it as such:
#include<iostream>
#define CALL(OBJECT, METHOD) \
const_cast<std::remove_const_t<std::remove_reference_t<decltype(OBJECT)>>&>(OBJECT).METHOD()
struct X { void foo () { std::cout << "X::foo()\n"; } };
int main ()
{
const X x;
CALL(x,foo);
}
Above code compiles fine for g++ & clang++. However with MSVC compiler it results in below error:
Left of
.foo()
must have aclass/struct/union
Is this a compiler bug? What can be a workaround fix within that macro?