[Bug c++/98992] attribute malloc error associating a member deallocator with an allocator
rdiezmail-gcc at yahoo dot de
gcc-bugzilla@gcc.gnu.org
Fri Jun 24 11:40:14 GMT 2022
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98992
R. Diez <rdiezmail-gcc at yahoo dot de> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |rdiezmail-gcc at yahoo dot de
--- Comment #1 from R. Diez <rdiezmail-gcc at yahoo dot de> ---
I have been using the following up to GCC 11.3:
struct MyClass
{
static void FreeMemory ( const void * pMem ) throw();
#if __GNUC_PREREQ(11, 0)
__attribute__ (( malloc, malloc( MyClass::FreeMemory, 1 ) ))
#else
__attribute__ (( malloc ))
#endif
static void * AllocMemory ( size_t Size ) throw();
[...]
};
However, GCC 12.1 does not want to accept it anymore:
error: 'malloc' attribute argument 1 does not name a function
I tried placing the attribute outside the class, like this:
__attribute__ (( malloc, malloc( MyClass::FreeMemory, 1 ) ))
void * MyClass::AllocMemory ( size_t Size ) throw()
{
return malloc( Size );
}
But then I got 2 errors:
error: 'static void MyClass::FreeMemory(const void*)' is protected within this
context
710 | __attribute__ (( malloc, malloc( MyClass::FreeMemory, 1 ) ))
| ^~~~~~~~~~
error: 'malloc' attribute argument 1 does not name a function
That cannot be right. GCC should not insist that the deallocator is public.
After all, the allocator AllocMemory is not public.
More information about the Gcc-bugs
mailing list