My understanding is that operator new cannot be templated (when declared using the parameters I have used.. (size_t)
The following compiles OK on mingw32 and arduino DUE, but not on other platforms e.g. linux.
Is there a bug in mingw32, or should this be allowed on other targets too ?
class t_other_class
{
public:
// This form of operator new is ***NOT*** allowed to be templated.
void* operator new ( size_t arg1 ) ;
// This form of operator new CAN be templated, and IS.
template<typename TF>
void* operator new ( size_t arg1
, int arg2
) ;
// This form of operator new CAN be templated, but IS NOT.
void* operator new ( size_t arg1
, int arg2
, int arg3
) ;
};
template <typename TCLASS>
class t_class
{
public:
// This form of operator new can NOT be templated, but is ALLOWED in mingw32
template<typename TF> // THIS SHOULD GENERATE AN ERROR
friend
void* t_other_class::operator new ( size_t arg1 ) ;
// Examples of templating..
template<typename TF>
friend /* IS templated in t_other_class*/
void* t_other_class::operator new ( size_t arg1
, int arg2
) ;
template<typename TF>
friend /* IS NOT templated in t_other_class*/
void* operator new ( size_t arg1
, int arg2
, int arg3
) ;
} ;
/*
OK
====
windows
GNU C++ (GCC) version 4.8.2 (i686-w64-mingw32)
DUE
gcc version 4.8.3 20140228 (release) [ARM/embedded-4_8-branch revision 208322] (GNU Tools for ARM Embedded Processors)
Error
====
linux
GNU C++ (Ubuntu 4.8.4-2ubuntu1~14.04.3) version 4.8.4 (i686-linux-gnu)
*/
I updated to latest Mingw and it now correctly reports the misuse of template declaration (as per other compilers). Looks like old version of mingw was the problem.