fork download
  1. class ExpressionTemplate
  2. {
  3. public:
  4. ExpressionTemplate() {}
  5. friend ExpressionTemplate f();
  6. private:
  7. ExpressionTemplate(const ExpressionTemplate&) {}
  8. ExpressionTemplate& operator=(const ExpressionTemplate&) {}
  9. };
  10.  
  11. ExpressionTemplate f() { return ExpressionTemplate(); }
  12.  
  13. class RealValue
  14. {
  15. public:
  16. RealValue& operator=(ExpressionTemplate&& x) { return *this; }
  17. RealValue(ExpressionTemplate&& x) {}
  18. RealValue() {}
  19. private:
  20. RealValue& operator=(const ExpressionTemplate& x) { return *this; }
  21. RealValue(const ExpressionTemplate& x) {}
  22. };
  23.  
  24. int main()
  25. {
  26. //auto x = f(); // Good, this throws a compile error.
  27. RealValue x1 = f(); // Good, this works.
  28. auto&& x2 = f();
  29. //RealValue x3 = x2; // Good, this throws a compile error.
  30. RealValue x4 = static_cast<ExpressionTemplate&&>(x2); // Bad, this compiles.
  31. }
Success #stdin #stdout 0s 2824KB
stdin
Standard input is empty
stdout
Standard output is empty