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(foo()); }
1 2 3
In function 'int main()': Line 16: error: invalid initialization of non-const reference of type 'foo&' from a temporary of type 'foo' compilation terminated due to -Wfatal-errors.