From: Eric Durant Subject: STL: MSVC++ 5.0 Bug in Date: 1997/11/10 Message-ID: <646pt3$mh4@netlab.cs.rpi.edu>#1/1 Sender: cppmods@netlab.cs.rpi.edu X-Submission-Address: c++-submit@netlab.cs.rpi.edu X-Original-Date: Sun, 09 Nov 1997 21:00:15 -0600 Organization: Milwaukee School of Engineering Newsgroups: comp.lang.c++.moderated The following source code demonstrates a type name identifier confusion error brought out by using a preprocessor macro to call a destructor in an instantiation of a templated class, specifically std::complex<>, in either: 1) Microsoft's Visual C++ v5.0 Preprocessor/Compiler or 2) Microsoft's implementation of the STL, specifically specialization code in -- Eric Durant http://www.msoe.edu/~durante/ Milwaukee School of Engineering ----------------------------------------------------------------- // Program Name: Complex Test (cplxtest.cpp) // Author: Eric Durant // Organization: Milwaukee School of Engineering // Date: Sunday 9 November 1997 // The following #define causes the compile to fail if T_CPLX is // float, double or long double (types with specialization code in // std::complex<>). The compile does not fail for other primitives, // such as int and long int (types without specialization code in // std::complex<>). #define T_CPLX double // The build fails with the following error: // C:\Program Files\DevStudio\VC\INCLUDE\xmemory(33) : error C2300: // 'Complex' : class does not have a destructor called '~_Ty' // For reference, lines 31 through 33 of are: // template inline // void _Destroy(_Ty _FARQ *_P) // {_DESTRUCTOR(_Ty, _P); } // Line 33 of makes an explicit destructor call using a // preprocessor macro. has specialization code for // instantiations of complex, where T is float, double or long // double. This specialization code uses the type name identifier _Ty, // which is also used by . The bug is probably one of the // following: // 1) The type identifier _Ty, used in both and , // collides because of the specialization code. // 2) A type name identifier in a preprocessor macro is taken as // literal text instead of a class or primitive type when certain // specialization code is used. // The example code follows. For clarity, member function definitions // (which are not required to demonstrate the bug) have been omitted. #include #include using namespace std; typedef complex primitiveComplex; class Complex : public primitiveComplex { public: Complex (); virtual ~Complex(); bool operator< (const Complex& right) const; }; void main () { vector X; } [ Send an empty e-mail to c++-help@netlab.cs.rpi.edu for info ] [ about comp.lang.c++.moderated. First time posters: do this! ]