2 years ago
#33505
iammilind
Why MSVC still compiles to error for calling a method after removing const-ness of the object?
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?
c++
visual-c++
compiler-errors
c++14
compiler-bug
0 Answers
Your Answer