IBM Support

Building C++ Test Driver script results an error C2661: 'new[]' : no overloaded function takes 3 parameters

Troubleshooting


Problem

Attempts to build IBM Rational Test RealTime C++ test driver script (.otd_aug.cpp) in component test results an the error "C2661: 'new[]' : no overloaded function takes 3 parameters".

Symptom

The full error message is as follows:

C:\Program Files\Microsoft Visual Studio\VC98\MFC\INCLUDE\afxtempl.h(330) : error C2661: 'new[]' : no overloaded function takes 3 parameters
C:\Program Files\Microsoft Visual Studio\VC98\MFC\INCLUDE\afxtempl.h(1566) : while compiling class-template member function 'void __thiscall CArray<struct TYPE_BUTTON,struct TYPE_BUTTON &>::SetSize(int,int)'

Cause

This problem happens when MFC collection template is used in source code under test.

When using MFC collection template classes, it includes the header file afxtempl.h that has the lines:


#ifdef _DEBUG

    static char _szAfxTempl[] = "afxtempl.h";

    #undef THIS_FILE

    #define THIS_FILE _szAfxTempl

    #endif

    ……

    #define new DEBUG_NEW


MFC redefines DEBUG_NEW to "operator new" to take a couple of extra arguments (the source file name and line number) for memory allocation tracking, and the compiler will translate it to use the overload method for "operator new" with 3 arguments in debug build, as declared in afx.h:


  // (simplified)

    #ifdef _DEBUG

    # define DEBUG_NEW new(THIS_FILE, __LINE__)

    #else

    # define DEBUG_NEW new

    #endif

    ……

    void* operator new(size_t nSize, LPCSTR lpszFileName, int nLine);


In Test RealTime, for memory allocation tracking it overrides the C++ "new" (and “delete”) function by defining an inline function in the instrumented code, while among the inline functions added to TDP, there is nothing to override "void* operator new(size_t nSize, LPCSTR lpszFileName, int nLine)".

Resolving The Problem

A request for enhancement (RFE) has been filed under RATLC01490524 to include this part in future release of the product.

WORKAROUND:

Add definitions of inline functions to support build in debug mode, which can be done by changing the original definition to RTRT_INLINE_NEW_DELETE into the following in “Library Settings > User-defined extra code” of the TDP.

=========================
#if defined _DEBUG

#define RTRT_INLINE_NEW_DELETE \
\
inline void *operator new(RTRT_SIZE_T size, const char *lpszFileName, int nLine) RTRT_NEW_THROW \
{ \
return _atp_alloc ( size ,1); \
} \
\
inline void *operator new[] (RTRT_SIZE_T size, const char *lpszFileName, int nLine) RTRT_NEW_THROW \
{ \
return _atp_alloc ( size ,2); \
} \
\
inline void operator delete ( void *ptr ) RTRT_DELETE_THROW \
{ \
_atp_freeT ( ptr,1); \
} \
\
inline void operator delete[] ( void *ptr ) RTRT_DELETE_THROW \
{ \
_atp_freeT ( ptr,2); \
} \
inline void *__cdecl operator new[](size_t, void *_Where) RTRT_NEW_THROW { return (_Where);} \
inline void __cdecl operator delete[](void *, void *) RTRT_NEW_THROW { }


#else


#define RTRT_INLINE_NEW_DELETE \
\
inline void *operator new(RTRT_SIZE_T size) RTRT_NEW_THROW \
{ \
return _atp_alloc ( size ,1); \
} \
\
inline void *operator new[] (RTRT_SIZE_T size) RTRT_NEW_THROW \
{ \
return _atp_alloc ( size ,2); \
} \
\
inline void operator delete ( void *ptr ) RTRT_DELETE_THROW \
{ \
_atp_freeT ( ptr,1); \
} \
\
inline void operator delete[] ( void *ptr ) RTRT_DELETE_THROW \
{ \
_atp_freeT ( ptr,2); \
} \
inline void *__cdecl operator new[](size_t, void *_Where) RTRT_NEW_THROW { return (_Where);} \
inline void __cdecl operator delete[](void *, void *) RTRT_NEW_THROW { }


#endif
=========================
 

[{"Product":{"code":"SSSHUF","label":"Rational Test RealTime"},"Business Unit":{"code":"BU053","label":"Cloud & Data Platform"},"Component":"Component Testing: C++","Platform":[{"code":"PF033","label":"Windows"}],"Version":"7.0;7.5;7.5.0.1","Edition":"","Line of Business":{"code":"LOB45","label":"Automation"}}]

Document Information

Modified date:
23 June 2018

UID

swg21402574