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.