// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
movq 0x5b16(%rip), %rdi      # 0x7fd0
leaq 0x2b93(%rip), %rsi      # 0x5054
movl $0x23, %edx
callq 0x21a0
movl $0x20, %edi
callq 0x2180
movq %rax, %rbx
leaq 0x10(%rax), %r15
movq %r15, (%rax)
leaq 0x2b92(%rip), %rsi      # 0x5078
leaq 0x2ba4(%rip), %rdx      # 0x5091
movq %rax, %rdi
callq 0x473e
movq 0x5ad4(%rip), %r14      # 0x7fd0
leaq 0x2b8f(%rip), %rsi      # 0x5092
movl $0x5, %edx
movq %r14, %rdi
callq 0x21a0
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
movq %r14, %rdi
callq 0x21a0
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x2160
movsbl %al, %esi
movq %r14, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x20d0
movq (%rbx), %rdi
cmpq %r15, %rdi
je 0x255c
movq (%r15), %rsi
incq %rsi
callq 0x2190
movl $0x4, %edi
callq 0x2180
movq %rax, %r14
movq %rax, %rdi
movl $0x1, %esi
callq 0x3a3c
movl (%r14), %esi
movq 0x5a50(%rip), %rbx      # 0x7fd0
movq %rbx, %rdi
callq 0x2240
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x2160
movsbl %al, %esi
movq %r15, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x20d0
movl (%r14), %esi
movq %rbx, %rdi
callq 0x2240
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x2160
movsbl %al, %esi
movq %r15, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x20d0
movq %r14, %rdi
callq 0x3abe
movl (%r14), %esi
movq %rbx, %rdi
callq 0x2240
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x2160
movsbl %al, %esi
movq %r15, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x20d0
movq %r14, %rdi
callq 0x3abe
movl $0x4, %esi
movq %r14, %rdi
callq 0x2190
movl $0x4, %edi
callq 0x2180
movq %rax, %r14
leaq 0x2a7b(%rip), %rsi      # 0x50c8
movl $0x2, %edx
movq %rbx, %rdi
callq 0x21a0
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2100
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x2160
movsbl %al, %esi
movq %r15, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x20d0
movl (%r14), %esi
movq %rbx, %rdi
callq 0x2240
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2160
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2040
movq %rax, %rdi
callq 0x20d0
movq %r14, %rdi
callq 0x3abe
movq %r14, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x2140
movq %rax, %r15
movl $0x4, %esi
movq %r14, %rdi
jmp 0x26f6
movq %rax, %r15
movl $0x20, %esi
movq %rbx, %rdi
callq 0x2190
movq %r15, %rdi
callq 0x2250