1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
class foo { friend int lvalue_only(foo &); int f() const { return 1; } }; int lvalue_only(foo & x) { return x.f(); } int main() { foo x; lvalue_only(x); lvalue_only(static_cast<foo&>(foo())); }
1 2 3
In function 'int main()': Line 15: error: invalid static_cast from type 'foo' to type 'foo&' compilation terminated due to -Wfatal-errors.