I am baffled by this:
#include <iostream>
struct X {};
void f( const X &x ) { std::cerr << &x << "\n"; }
static X x;
int main()
{
f( x ); // Off stack address
f( false ? X() : x ); // Different address on stack.
}
Why would the second invocation of f make a temporary copy?
Edit: This question is not so much about the type X, but the fact that a copy is made. I was missing the sublety of value categories from the accepted answer and had expected f's parameter to bind on either x or X() directly like it does when rephrasing this as an if statement.