fork download
  1. struct Foo
  2. {
  3. int i;
  4. };
  5.  
  6. Foo create_foo()
  7. {
  8. return { 42 };
  9. }
  10.  
  11. int main()
  12. {
  13. Foo& my_foo = create_foo();
  14. my_foo.i = 33; // Undefined behaviour!
  15. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function 'int main()':
prog.cpp:13:26: error: invalid initialization of non-const reference of type 'Foo&' from an rvalue of type 'Foo'
  Foo& my_foo = create_foo();
                          ^
stdout
Standard output is empty