class ExpressionTemplate
{
public:
ExpressionTemplate() {}
friend ExpressionTemplate f();
private:
ExpressionTemplate(const ExpressionTemplate&) {}
ExpressionTemplate& operator=(const ExpressionTemplate&) {}
};
ExpressionTemplate f() { return ExpressionTemplate(); }
class RealValue
{
public:
RealValue& operator=(ExpressionTemplate&& x) { return *this; }
RealValue(ExpressionTemplate&& x) {}
RealValue() {}
private:
RealValue& operator=(const ExpressionTemplate& x) { return *this; }
RealValue(const ExpressionTemplate& x) {}
};
int main()
{
//auto x = f(); // Good, this throws a compile error.
RealValue x1 = f(); // Good, this works.
auto&& x2 = f();
//RealValue x3 = x2; // Good, this throws a compile error.
RealValue x4 = static_cast<ExpressionTemplate&&>(x2); // Bad, this compiles.
}
Y2xhc3MgRXhwcmVzc2lvblRlbXBsYXRlCnsKcHVibGljOgogIEV4cHJlc3Npb25UZW1wbGF0ZSgpIHt9CiAgZnJpZW5kIEV4cHJlc3Npb25UZW1wbGF0ZSBmKCk7CnByaXZhdGU6CiAgRXhwcmVzc2lvblRlbXBsYXRlKGNvbnN0IEV4cHJlc3Npb25UZW1wbGF0ZSYpIHt9CiAgRXhwcmVzc2lvblRlbXBsYXRlJiBvcGVyYXRvcj0oY29uc3QgRXhwcmVzc2lvblRlbXBsYXRlJikge30KfTsKCkV4cHJlc3Npb25UZW1wbGF0ZSBmKCkgeyByZXR1cm4gRXhwcmVzc2lvblRlbXBsYXRlKCk7IH0KCmNsYXNzIFJlYWxWYWx1ZQp7CnB1YmxpYzoKICBSZWFsVmFsdWUmIG9wZXJhdG9yPShFeHByZXNzaW9uVGVtcGxhdGUmJiB4KSB7IHJldHVybiAqdGhpczsgfQogIFJlYWxWYWx1ZShFeHByZXNzaW9uVGVtcGxhdGUmJiB4KSB7fQogIFJlYWxWYWx1ZSgpIHt9CnByaXZhdGU6CiAgUmVhbFZhbHVlJiBvcGVyYXRvcj0oY29uc3QgRXhwcmVzc2lvblRlbXBsYXRlJiB4KSB7IHJldHVybiAqdGhpczsgfQogIFJ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