Redefining keywords? (was: Assigning __FILE__ to a char* gives warning)
allan.mcrae@gmail.com wrote:
As part of a very simple memory leak detector, I am trying to store
the value of __FILE__ in a char*. Since gcc4.2 I get the following
warning...
warning: deprecated conversion from string constant to 'char*'
From what I understand about __FILE__ it returns a const char[]
object. The macro of delete assigns this to a global char* which is
used to track where deletions were made. Something like:
#define delete delete_FILE_ = __FILE__, \
delete_LINE_ = __LINE__, \
delete
Removing the delete_FILE_ = __FILE__ line stops the error. How do I
do this properly?
I have a question about the above... I also have code that redefines new
and delete for leak detection, but I'm not really sure if redefining
keywords like that is appropriate. Is it allowed by the standard?
My code looks something like this:
void* operator new( std::size_t size, const char* fileName, int line );
void* operator new[]( std::size_t size, const char* fileName, int line );
#define DEBUG_NEW new(__FILE__, __LINE__)
#define new DEBUG_NEW
void operator delete( void* address ) throw();
void operator delete[]( void* address ) throw();