Article ID: 133068
Article Last Modified on 7/5/2005
APPLIES TO
- Microsoft C/C++ Professional Development System 7.0
- Microsoft Visual C++ 1.0 Professional Edition
- Microsoft Visual C++ 1.5 Professional Edition
- Microsoft Visual C++ 1.51
- Microsoft Visual C++ 1.52 Professional Edition
- Microsoft Visual C++ 5.0 Learning Edition
- Microsoft Visual C++ 5.0 Learning Edition
- Microsoft Visual C++ 4.2 Enterprise Edition
- Microsoft Visual C++ 2.0 Professional Edition
- Microsoft Visual C++ 4.0 Professional Edition
- Microsoft Visual C++ 4.1 Subscription
- Microsoft Visual C++ 4.2 Professional Edition
This article was previously published under Q133068
SYMPTOMS
The sample code fragment listed at the end of this article incorrectly deletes a typedef of a pointer to a structure, which generates the following compiler errors:
- For Visual C++ 4.2 for Windows NT:
- For Visual C++ 4.1 for Windows NT:
- For Visual C++ 4.0 for Windows NT:
- For Visual C++ 2.x for Windows NT:
- For Visual C++ 1.0 for Windows NT:
- For Visual C++ version 1.5x for Windows:
- For Visual C++ version 1.0 for Windows:
- For C/C++ version 7.0:
RESOLUTION
The above error messages are misleading and do not point out the real problem, which is that you cannot delete a typedef. Additionally, the operand of delete must be a pointer returned by the new operator. Using delete on a pointer to an object not allocated with new gives unpredictable results.
STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article.
MORE INFORMATION
Sample Code to Reproduce Problem
/* Compile options needed: none */ typedef struct { int x; }MY_STRUCT, *LPMY_STRUCT; LPMY_STRUCT pMyStruct = new MY_STRUCT; void MyTestFunction() { delete pMyStruct; // ok. delete LPMY_STRUCT; // Can not delete a type. }
Additional query words: 8.0 8.0c 8.00 8.00c 9.0 9.00 9.1 9.10 10.00 10.10 10.20
Keywords: kbbug kbcpponly kbcompiler KB133068