// File: /workspace/github_cpp_makefile_star2_O2/MingYueRuYa[P]cprimeprimecode/memory_manager.cpp
// Function: demo07::test_overload_placement_new()
void test_overload_placement_new()
{
	cout << "\n\n\ntest_overload_placement_new()..........\n";

	Foo start; 							//Foo:Foo
	cout << "Foo start" << endl;

	Foo *p1 = new Foo;					//op-new(size_t)
	cout << "new Foo" << endl;

	Foo *p2 = new (&start)Foo;			//op-new(size_t, void *)
	cout << "new (&start)Foo" << endl;

	Foo *p3 = new (100)Foo;				//op-new(size_t, long)
	cout << "new (100)Foo" << endl;

  	Foo *p4 = new (100, 'a')Foo;		//op-new(size_t, long, char)
	cout << "new (100, 'a')Foo" << endl;

	Foo *p5 = new (100) Foo(1);			//op-new(size_t, long) op-del(void *,long)
	cout << "new (100) Foo(1)" << endl;

	Foo *p6 = new (100, 'a') Foo(2);
	cout << "new (100, 'a') Foo(2)" << endl;

	Foo *p7 = new (&start) Foo(1);
	cout << "new (&start) Foo(1)" << endl;

	Foo *p8 = new Foo(1);
	cout << "new Foo(1)" << endl;
	//result:
		// test_overload_placement_new()..........
		// Foo:Foo()
		// Foo start
		// operator new(size_t size), size=4
		// Foo:Foo()
		// new Foo
		// operator new(size_t size, void *start), size= 4 start=0x7e95e58c
		// Foo:Foo()
		// new (&start)Foo
		// operator new(size_t size, long extra) size=4 extra:100
		// Foo:Foo()
		// new (100)Foo
		// operator new(size_t size, long extra, char init) size=4 extra= 100 init=a
		// Foo:Foo()
		// new (100, 'a')Foo
		// operator new(size_t size, long extra) size=4 extra:100
		// Foo:Foo(int)
		// new (100) Foo(1)
		// operator new(size_t size, long extra, char init) size=4 extra= 100 init=a
		// Foo:Foo(int)
		// new (100, 'a') Foo(2)
		// operator new(size_t size, void *start), size= 4 start=0x7e95e58c
		// Foo:Foo(int)
		// new (&start) Foo(1)
		// operator new(size_t size), size=4
		// Foo:Foo(int)
		// new Foo(1)
		// [notice:在4.9上当ctor爆出异常时G4.9没有调用对应的operator delete(void *, long)]
		// [但在G2.9确实是可以的]
		// terminate called after throwing an instance of 'demo07::Bad'
		// Aborted
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0x10, %rsp
movq 0x4104(%rip), %rbx      # 0x6fd0
leaq 0x1338(%rip), %rsi      # 0x420b
movq %rbx, %rdi
callq 0x2170
leaq -0x14(%rbp), %rdi
callq 0x35f4
leaq 0x134c(%rip), %rsi      # 0x4237
movq %rbx, %rdi
callq 0x2170
movq %rax, %rdi
callq 0x2090
pushq $0x4
popq %rdi
callq 0x3614
movq %rax, %r14
movq %rax, %rdi
callq 0x35f4
movq 0x40bb(%rip), %rdi      # 0x6fd0
leaq 0x1325(%rip), %rsi      # 0x4241
callq 0x2170
movq %rax, %rdi
callq 0x2090
pushq $0x4
popq %rdi
leaq -0x14(%rbp), %rsi
callq 0x367c
movq %rax, %r14
movq %rax, %rdi
callq 0x35f4
movq 0x4089(%rip), %rdi      # 0x6fd0
leaq 0x12fb(%rip), %rsi      # 0x4249
callq 0x2170
movq %rax, %rdi
callq 0x2090
pushq $0x4
popq %rdi
pushq $0x64
popq %rsi
callq 0x36fc
movq %rax, %r14
movq %rax, %rdi
callq 0x35f4
movq 0x4058(%rip), %rdi      # 0x6fd0
leaq 0x12da(%rip), %rsi      # 0x4259
callq 0x2170
movq %rax, %rdi
callq 0x2090
pushq $0x4
popq %rdi
pushq $0x64
popq %rsi
pushq $0x61
popq %rdx
callq 0x3782
movq %rax, %r14
movq %rax, %rdi
callq 0x35f4
movq 0x4024(%rip), %rdi      # 0x6fd0
leaq 0x12b3(%rip), %rsi      # 0x4266
callq 0x2170
movq %rax, %rdi
callq 0x2090
pushq $0x4
popq %rdi
pushq $0x64
popq %rsi
callq 0x36fc
movq %rax, %r14
pushq $0x1
popq %rsi
movq %rax, %rdi
callq 0x382e
movq 0x3ff0(%rip), %rdi      # 0x6fd0
leaq 0x1291(%rip), %rsi      # 0x4278
callq 0x2170
movq %rax, %rdi
callq 0x2090
pushq $0x4
popq %rdi
pushq $0x64
popq %rsi
pushq $0x61
popq %rdx
callq 0x3782
movq %rax, %r14
pushq $0x2
popq %rsi
movq %rax, %rdi
callq 0x382e
movq 0x3fb9(%rip), %rdi      # 0x6fd0
leaq 0x126b(%rip), %rsi      # 0x4289
callq 0x2170
movq %rax, %rdi
callq 0x2090
pushq $0x4
popq %rdi
leaq -0x14(%rbp), %rsi
callq 0x367c
movq %rax, %r14
pushq $0x1
popq %rsi
movq %rax, %rdi
callq 0x382e
movq 0x3f84(%rip), %rdi      # 0x6fd0
leaq 0x124c(%rip), %rsi      # 0x429f
callq 0x2170
movq %rax, %rdi
callq 0x2090
pushq $0x4
popq %rdi
callq 0x3614
movq %rax, %r14
pushq $0x1
popq %rsi
movq %rax, %rdi
callq 0x382e
movq 0x3f53(%rip), %rdi      # 0x6fd0
leaq 0x122f(%rip), %rsi      # 0x42b3
callq 0x2170
movq %rax, %rdi
callq 0x2090
addq $0x10, %rsp
popq %rbx
popq %r14
popq %rbp
retq
jmp 0x30d6
jmp 0x30c5
jmp 0x30a2
jmp 0x30b5
movq %rax, %rbx
pushq $0x64
popq %rsi
pushq $0x61
popq %rdx
movq %r14, %rdi
callq 0x3804
jmp 0x30e4
movq %rax, %rbx
pushq $0x64
popq %rsi
movq %r14, %rdi
callq 0x3758
jmp 0x30e4
movq %rax, %rbx
leaq -0x14(%rbp), %rsi
movq %r14, %rdi
callq 0x36d2
jmp 0x30e4
movq %rax, %rbx
pushq $0x4
popq %rsi
movq %r14, %rdi
callq 0x3652
movq %rbx, %rdi
callq 0x2250