I think your code should work (as on GCC or Clang), according to
5 Expressions [expr]
8 In some contexts, unevaluated operands appear (5.2.8, 5.3.3, 5.3.7, 7.1.6.2). An unevaluated operand is not evaluated. An unevaluated operand is considered a full-expression. [Note: In an unevaluated operand, a non-static class member may be named (5.1) and naming of objects or functions does not, by itself, require that a definition be provided (3.2). — end note ]
It seems that VC++ does not implement what the note clarifies, so you need a (faked) instance as a work-around to make VC++ happy. This should work:
void print()
{
std::cout << sizeof(std::declval<bar>().member_) << std::endl;
}
Note that I removed the decltype
as sizeof
can work on expressions directly.