// File: MingYueRuYa[P]cprimeprimecode/memory_manager.cpp
// Function: demo02::test_call_ctor_directory()
void test_call_ctor_directory()
{
	cout << "\ntest_call_ctor_directory().......\n";
	string *pstr = new string("liushixiong like program!");
	cout << "str= " << *pstr << endl;
	//! pstr->string::string("demo2"); 
	//[Error] 'class std::basic_string<char>' has no member named 'string'
 
	pstr->~string(); //crash ----其语法语义是正确的，
					 //crash只因为上一行被remark起来[侯捷]，
					 //但是实际情况在pi环境下测试并没有crash，此处灰色地带

	A *pA = new A(1); //ctor. this=0x16d8048 id=1
	cout << pA->id << endl; // 1
	//! pA->A::A(3); //in VC6 : ctor, this0013FF60 id 3
					 //in vs2013 : ctor, this0013FF60 id 3
		 //in GCC : [Error] cannot call constructor ‘demo02::A::A’ directly

	cout << pA->id << endl; 	//in VC6 : 3
								//in GCC : 1
	pA->~A(); 					//dtor, this=0xd37048 id=1，手动调用析构函数
	cout << pA->id << endl; 	//测试内存是否被手动调用析构函数释放，\
								//但其实内存并没有释放

	delete pA;					// dtor, this=0x16d8048 id=1

	//simulate new
	void *p = ::operator new(sizeof(A));
	cout << "p=" << p << endl;		//this=000307A8
	pA = static_cast<A *>(p);
	//! pA->A(2); 					//[Error]: invalid use of ‘demo02::A::A’
	//!	pA->A::A(2);				//in VC6 : ctor. this=000307A8 id=2
									//in GCC : [Error] cannot call constructor 'demo02::A::A' directly 

	cout << pA->id << endl;			//in VC6 : 2
									//in GCC : 0

	//simulate delete
	pA->~A(); 						//dtor. this=000307A8, id=0
	::operator delete(pA);			//free();	
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq 0x6919(%rip), %rdi      # 0x8fd8
leaq 0x3972(%rip), %rsi      # 0x6038
callq 0x2190
movl $0x20, %edi
callq 0x21a0
movq %rax, -0x40(%rbp)
movq %rax, -0x48(%rbp)
movb $0x1, -0x1d(%rbp)
leaq -0x9(%rbp), %rdi
movq %rdi, -0x38(%rbp)
callq 0x2310
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rdx
leaq 0x395f(%rip), %rsi      # 0x605c
callq 0x42f0
jmp 0x2704
movb $0x0, -0x1d(%rbp)
leaq -0x9(%rbp), %rdi
callq 0x21e0
movq -0x48(%rbp), %rax
movq %rax, -0x8(%rbp)
movq 0x68b8(%rip), %rdi      # 0x8fd8
leaq 0x394f(%rip), %rsi      # 0x6076
callq 0x2190
movq %rax, %rdi
movq -0x8(%rbp), %rsi
callq 0x2170
movq %rax, %rdi
movq 0x6876(%rip), %rsi      # 0x8fb8
callq 0x21c0
movq -0x8(%rbp), %rdi
callq 0x20d0
movl $0x4, %edi
callq 0x21a0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x50(%rbp)
movl $0x1, %esi
callq 0x43a0
jmp 0x2770
movq -0x50(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movl (%rax), %esi
movq 0x6853(%rip), %rdi      # 0x8fd8
callq 0x22f0
movq %rax, %rdi
movq 0x6824(%rip), %rsi      # 0x8fb8
callq 0x21c0
movq -0x28(%rbp), %rax
movl (%rax), %esi
movq 0x6832(%rip), %rdi      # 0x8fd8
callq 0x22f0
movq %rax, %rdi
movq 0x6803(%rip), %rsi      # 0x8fb8
callq 0x21c0
movq -0x28(%rbp), %rdi
callq 0x4410
movq -0x28(%rbp), %rax
movl (%rax), %esi
movq 0x6808(%rip), %rdi      # 0x8fd8
callq 0x22f0
movq %rax, %rdi
movq 0x67d9(%rip), %rsi      # 0x8fb8
callq 0x21c0
movq -0x28(%rbp), %rax
movq %rax, -0x58(%rbp)
cmpq $0x0, %rax
je 0x2809
movq -0x58(%rbp), %rdi
callq 0x4410
movq -0x58(%rbp), %rdi
movl $0x4, %esi
callq 0x21b0
movl $0x4, %edi
callq 0x21a0
movq %rax, -0x30(%rbp)
movq 0x67ba(%rip), %rdi      # 0x8fd8
leaq 0x3887(%rip), %rsi      # 0x60ac
callq 0x2190
movq %rax, %rdi
movq -0x30(%rbp), %rsi
callq 0x2130
movq %rax, %rdi
movq 0x6778(%rip), %rsi      # 0x8fb8
callq 0x21c0
movq -0x30(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movl (%rax), %esi
movq 0x677e(%rip), %rdi      # 0x8fd8
callq 0x22f0
movq %rax, %rdi
movq 0x674f(%rip), %rsi      # 0x8fb8
callq 0x21c0
movq -0x28(%rbp), %rdi
callq 0x4410
movq -0x28(%rbp), %rdi
callq 0x2180
addq $0x60, %rsp
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
leaq -0x9(%rbp), %rdi
callq 0x21e0
testb $0x1, -0x1d(%rbp)
jne 0x28a3
jmp 0x28b1
movq -0x48(%rbp), %rdi
movl $0x20, %esi
callq 0x21b0
jmp 0x28cd
movq -0x50(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x18(%rbp)
movl %eax, -0x1c(%rbp)
movl $0x4, %esi
callq 0x21b0
movq -0x18(%rbp), %rdi
callq 0x2300
nopw %cs:(%rax,%rax)