CSimpleMap SetAtIndex do not call a ditructor! - by Aleksandr Tokarev

Status : 

  By Design<br /><br />
		The product team believes this item works according to its intended design.<br /><br />
		A more detailed explanation for the resolution of this particular item may have been provided in the comments section.


1
0
Sign in
to vote
ID 298324 Comments
Status Closed Workarounds
Type Bug Repros 1
Opened 9/16/2007 2:30:47 PM
Access Restriction Public

Description

CSimpleMap in ATL do not call a distructor before calling InternalSetAtIndex

BOOL SetAtIndex(int nIndex, const TKey& key, const TVal& val)
{
	if (nIndex < 0 || nIndex >= m_nSize)
		return FALSE;
	InternalSetAtIndex(nIndex, key, val);
	return TRUE;
}

as a result when you first calls SetAtIndex everything works fine, but the second time to the same location distructor for previos stored Key and Value are not called.

This is a correct implementation...

BOOL SetAtIndex(int nIndex, const TKey& key, const TVal& val)
{
	if (nIndex < 0 || nIndex >= m_nSize)
		return FALSE;
	m_aKey[nIndex].~TKey();
	m_aVal[nIndex].~TVal();
	InternalSetAtIndex(nIndex, key, val);
	return TRUE;
}
Sign in to post a comment.
Posted by Ale [MSFT] on 9/25/2008 at 2:22 PM
The Visual C++ team has triaged the issue you reported. The issue has been resolved during triage with the following message:

CSimpleMap wasn't really designed to work for types that needed destruction. The docs state it is limited and you should use CAtlMap instead.

For further information, you may want to consult one of these resources:
1. Visual C++ triage guidelines:
        http://blogs.msdn.com/vcblog/articles/621116.aspx
2. MSDN forums:
        http://forums.microsoft.com/msdn/default.aspx

Thank you for taking time to send us feedback,
The Visual C++ Team
Posted by Microsoft on 9/16/2007 at 11:40 PM
Thanks for your feedback. We have reproduced this bug on Visual Studio 2008 Beta 2, and we are sending this bug to the appropriate group within the VisualStudio Product Team for triage and resolution.

Thank you,
Visual Studio Product Team.
Posted by Microsoft on 9/16/2007 at 7:24 PM
Thank you for your feedback. We are currently investigating. If this issue is urgent, please call support directly (see http://support.microsoft.com).

Thank you,
Visual Studio Product Team