You can use an expression such as:
sizeof Foo().bar
As the argument of sizeof
isn’t evaluated, only its type, no temporary is actually created.
If Foo
wasn’t default constructible (unlike your example), you’d have to use a different expression such as one involving a pointer. (Thanks to Mike Seymour)
sizeof ((Foo*)0)->bar