fork(2) download
  1. #include <iostream>
  2.  
  3. struct Foo {
  4. Foo() = default;
  5. Foo(Foo &&) {}
  6. };
  7.  
  8. struct Bar {
  9. Bar() = default;
  10. //Bar(const Bar &) = default;
  11. Bar(Bar &&) = default;
  12. };
  13.  
  14. struct Empty
  15. {};
  16.  
  17. Foo GetFoo() {
  18. Foo foo;
  19. std::cout << "GetFoo:" << &foo << std::endl;
  20. return foo;
  21. }
  22.  
  23. Bar GetBar() {
  24. Bar bar;
  25. std::cout << "GetBar:" << &bar << std::endl;
  26. return bar;
  27. }
  28.  
  29. Empty GetEmpty() {
  30. Empty e;
  31. std::cout << "GetEmpty:" << &e << std::endl;
  32. return e;
  33. }
  34.  
  35. int main() {
  36. // RVO OK
  37. Foo foo = GetFoo();
  38. std::cout << "foo:" << &foo << std::endl<< std::endl;
  39. // RVO GG
  40. Bar bar = GetBar();
  41. std::cout << "bar:" << &bar << std::endl<< std::endl;
  42. // RVO GG
  43. Empty empty = GetEmpty();
  44. std::cout << "empty:" << &empty << std::endl<< std::endl;
  45. return 0;
  46. }
  47.  
Success #stdin #stdout 0s 15240KB
stdin
Standard input is empty
stdout
GetFoo:0x7fff214a60ed
foo:0x7fff214a60ed

GetBar:0x7fff214a60bf
bar:0x7fff214a60ee

GetEmpty:0x7fff214a60bf
empty:0x7fff214a60ef