Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does the error "non-placement deallocation function"?

Tags:

c++

I am getting the following error while compiling the serna-free package:

build/buildd-serna-free_4.3.0.20110221-2-i386-pAsDoD/serna-free-4.3.0.20110221/
  sfworks/common/RefCntStorage.h:76:10:
error: non-placement deallocation function 'static void
StringPrivate::RefCntData<E>::operator
delete(void*,StringPrivate::size_type) [with E = QChar,
StringPrivate::size_type = unsigned int]'
/build/buildd-serna-free_4.3.0.20110221-2-i386-pAsDoD/serna-free-4.3.0.20110221/
   sfworks/common/RefCntStorage.h:135:9:
error: selected for placement delete

Code looks like:

void operator delete(void* p, size_type)
{
    ::operator delete(p);
}
like image 286
malat Avatar asked Aug 27 '26 22:08

malat


1 Answers

I think that the problem comes from this wording in the spec:

If class T does not declare such an operator delete but does declare a member deallocation function named operator delete with exactly two parameters, the second of which has type std::size_t (18.1), then this function is a usual deallocation function

This would mean that if you tried to declare a pair operator new and operator delete that took a size_t as the second parameter, the compiler would think that your operator delete with this signature:

void operator delete (void* memory, size_t arg)

was the standard (non-placement) deallocator rather than the placement deallocator that's supposed to match operator new(void*, size_t).

What's odd about this is that nowhere in the spec does it say that this should cause a compiler error. In fact, the spec just says that if you have this error, then if the custom new throws an exception then the memory just won't get cleaned up. If anyone knows why g++ is reporting this as an error, I'd love to know why (especially if I'm wrong and this really is supposed to be illegal).

EDIT: Ah! The problem seems to be from C++0x. According to the most recent draft of the new standard, §3.5.4/20:

If the lookup finds the two-parameter form of a usual deallocation function (3.7.4.2) and that function, considered as a placement deallocation function, would have been selected as a match for the allocation function, the program is ill-formed.

It specifically lists doing this as an example of what would cause the breakage. The fact that this is new in C++0x would explain why the error only started popping up in the newest version of g++.

like image 174
templatetypedef Avatar answered Aug 30 '26 10:08

templatetypedef



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!