C++/CLI 컴파일러의 == 연산자 버그?

  • Post author:
  • Post category:
  • Post comments:0 Comments
  • Post last modified:October 14, 2008
property CInventoryBagManaged^ BagInventory
{
	CInventoryBagManaged^ get()
	{
		if(m_BagInventory == nullptr)
		{
			CInventoryBag* inventory =  m_NativeObject->GetBagInventory();
			if(inventory == NULL)
				return nullptr;

			m_BagInventory = gcnew CInventoryBagManaged(inventory);
		}
		return m_BagInventory;
	}
}

해당 클래스의 전체 소스코드를 공개할 수야 없는 노릇이니 문제가 된 프로퍼티만 적었다. 해당 클래스엔 이와 유사한 프로퍼티가 여러 개 있는데 유독 이 프로퍼티에서만 문제가 발생했다. 뭔 문제인가 하니, if(m_BagInventory == nullptr)에서 널 참조 예외가 계속 튀어나왔다. 어라? m_BagInventory가 널인지 확인하라니까 널 참조를 내보내? 미친 건가?

디버거 창에서 m_BagInventory==nullptr이냐고 물으니까 true란다. 도대체 어쩌라고?

결국 컴파일러 버그인가 싶어 코드를 if(nullptr == m_BagInventory)라고 고쳐봤다. 그러니까 더 이상 널 참조 예외가 안 난다. 참 난감한 일이다. 이런 구조를 가진 프로퍼티가 여러 개 있는데 유독 이번만 문제가 발생했다. 일단 문제의 재발 방지 차원에서 앞으론 if(nullptr == m_BagInventory) 식으로 코드를 짜야겠다.

Author Details
Kubernetes, DevSecOps, AWS, 클라우드 보안, 클라우드 비용관리, SaaS 의 활용과 내재화 등 소프트웨어 개발 전반에 도움이 필요하다면 도움을 요청하세요. 지인이라면 가볍게 도와드리겠습니다. 전문적인 도움이 필요하다면 저의 현업에 방해가 되지 않는 선에서 협의가능합니다.
0 0 votes
Article Rating
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Inline Feedbacks
View all comments