#include <iostream>
#include <algorithm>
using namespace std;
#define print_func() cout << __PRETTY_FUNCTION__ << endl
struct A {
A( ) { print_func( ) ; }
A( A & ) { print_func( ) ; }
A( A && ) { print_func( ) ; }
A( const A & ) { print_func( ) ; }
A( const A && ) { print_func( ) ; }
~A( ) { print_func( ) ; }
} ;
void bad_free( A && a) {
cout << "inside bad_free, before move" << endl;
A && clever = move( a ) ;
cout << "inside bad_free, after move" << endl;
// 'clever' should be the last reference to a?
}
int main( ) {
{
cout << "test1 start" << endl;
bad_free( A( ) ) ;
cout << "test1 end" << endl;
}
{
cout << "test2 start" << endl;
A x;
cout << "test2 before call" << endl;
bad_free( move( x) ) ;
cout << "test2 end" << endl;
}
return 0 ;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8YWxnb3JpdGhtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKI2RlZmluZSBwcmludF9mdW5jKCkgY291dCA8PCBfX1BSRVRUWV9GVU5DVElPTl9fIDw8IGVuZGwKCnN0cnVjdCBBIHsKCUEoKSB7cHJpbnRfZnVuYygpO30KCUEoQSAmKSB7cHJpbnRfZnVuYygpO30KCUEoQSAmJikge3ByaW50X2Z1bmMoKTt9CglBKGNvbnN0IEEgJikge3ByaW50X2Z1bmMoKTt9CglBKGNvbnN0IEEgJiYpIHtwcmludF9mdW5jKCk7fQoJfkEoKSB7cHJpbnRfZnVuYygpO30KfTsKCnZvaWQgYmFkX2ZyZWUoQSAmJiBhKSB7Cgljb3V0IDw8ICJpbnNpZGUgYmFkX2ZyZWUsIGJlZm9yZSBtb3ZlIiA8PCBlbmRsOwogICAgQSAmJiBjbGV2ZXIgPSBtb3ZlKCBhICk7Cgljb3V0IDw8ICJpbnNpZGUgYmFkX2ZyZWUsIGFmdGVyIG1vdmUiIDw8IGVuZGw7CiAgICAvLyAnY2xldmVyJyBzaG91bGQgYmUgdGhlIGxhc3QgcmVmZXJlbmNlIHRvIGE/Cn0KCmludCBtYWluKCkgewoJewo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