[Bug c++/29164] Overloaded operator delete[] doesn't get called
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=29164 Jonathan Wakely changed: What|Removed |Added Status|NEW |RESOLVED Resolution|--- |INVALID Known to fail|| --- Comment #11 from Jonathan Wakely --- C++03 [expr.delete] p2: > In either alternative, if the value of the operand of delete is the null > pointer the operation has no effect. That wording was changed by http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#348 C++11 [expr.delete] p7: > If the value of the operand of the delete-expression is not a null pointer > value, the delete-expression will call a deallocation function (3.7.4.2). > Otherwise, it is unspecified whether the deallocation function will be > called. So in C++03 the delete expressions "have no effect" but that was clarified to mean that the deallocation functions might not be called, which makes GCC's behaviour correct. Prior to r259772 ("PR c++/61982 - dead stores to destroyed objects") GCC was inconsistent, calling the operator for "delete[] p" but not "delete[] p". Now it matches Clang's behaviour and neither calls the operator when p is null. I don't think there's any bug here anyway.
[Bug c++/29164] Overloaded operator delete[] doesn't get called
--- Comment #10 from Andreas dot Kowarz at tu-dresden dot de 2007-03-12 09:30 --- THS (The Holy Standard :-) ) 3.7.4.2/3 reads to me that for standard library implementations the delete operators must be called in any case but return immediately if the first argument is NULL = NULL-check inside the operator. Taking the context into account, it reads to me as if standard library delete calls can be treated as special cases. In the more general case, i.e., the user supplied delete operators, no special assumptions can be done. Again, the operators must be called in any case but it is up to the user to handle special cases correctly. Whatever the latter may look like. Andreas -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29164
[Bug c++/29164] Overloaded operator delete[] doesn't get called
--- Comment #9 from fang at csl dot cornell dot edu 2007-03-11 03:47 --- In fact, I'm having trouble reproducing the problem when operator delete [] returns anything BUT NULL. It's as if, the actual call to operator delete [] is guarded by a NULL check. Now, if I'm RTHS (reading the holy standard) correctly, in [basic.stc.dynamic.deallocation] 3.7.4.2/3: The value of the first argument supplied to a deallocation functions may be a null pointer value; if so, and if the deallocation function is one supplied in the standard library, the call has no effect. This seems to apply specifically to the standard library, but not necessarily non-standard implementations of the operator. Does that mean that the call to operator delete [] can be elided legally if the argument is NULL, or that the implementation of operator delete [] (NULL) is required to have no effect? -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29164
[Bug c++/29164] Overloaded operator delete[] doesn't get called
--- Comment #8 from Andreas dot Kowarz at tu-dresden dot de 2007-03-09 09:37 --- It seems that the bug triggers only when returning NULL in the new operators. Returning something different ( tested with (void *)1 ) is a workaround for the problem. Checking for not returning NULL in the new operators seems reasonable even if it does not solve the mentioned mis-compilation of the delete operators. Tested for - g++ 3.2.3 - g++ 4.1.1 - icpc 9.1 (returning NULL prevents both delete operators from being called correctly) Andreas -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29164
[Bug c++/29164] Overloaded operator delete[] doesn't get called
--- Comment #5 from fang at csl dot cornell dot edu 2007-03-08 21:49 --- Ouch, this one seems particularly nasty to me... seeings as this isn't a regression (at least from 2.95), I don't expect this to be fixed for 4.2. Is there any chance of this getting attention on the (4.3) mainline? I'm having trouble finding an elegant workaround to this -- I'm expecting a smart pointer-to-array class to 'do the right thing' during destruction (call the right operator delete []), but I can't just force it to call Class::operator delete [], if the Class doesn't override it. I just might have to use the force (SFINAE)... Incidentally, also known to fail 3.4.6, 4.0.1, 4.1.0. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29164
[Bug c++/29164] Overloaded operator delete[] doesn't get called
--- Comment #6 from fang at csl dot cornell dot edu 2007-03-08 22:58 --- Subject: Re: Overloaded operator delete[] doesn't get called This following test case is 'interesting': 8 snip 8- #include iostream using std::cout; class one_array_only { private: static one_array_only pool[256]; public: static void * operator new[] (std::size_t size) throw() { cout class new[] operator\n; #if WTF return pool; #else return NULL; #endif } static void operator delete[] (void *p) throw() { cout class delete[] operator\n; } }; one_array_only one_array_only::pool[256]; int main(int argc, char* argv[]) { one_array_only* p = new one_array_only[12]; delete [] p; return 0; } 8 snip 8- Above, in operator new[], If WTF is false, returning NULL, I reproduce the same error (missing call to class operator delete []). If WTF is true (returning pool), the right operator delete [] is called. // output with WTF false class new[] operator // output with WTF true class new[] operator class delete[] operator Tested on: powerpc-apple-darwin8-g++-4.0.1 Why on earth would the definition inside operator new[] influence whether or not operator delete[] is called? Fang -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29164
[Bug c++/29164] Overloaded operator delete[] doesn't get called
--- Comment #7 from fang at csl dot cornell dot edu 2007-03-08 23:41 --- Subject: Re: Overloaded operator delete[] doesn't get called Above, in operator new[], If WTF is false, returning NULL, I reproduce the same error (missing call to class operator delete []). If WTF is true (returning pool), the right operator delete [] is called. // output with WTF false class new[] operator // output with WTF true class new[] operator class delete[] operator Tested on: powerpc-apple-darwin8-g++-4.0.1 The same result ALSO happens if I de-inline the class operator new/delete [], and compile their definitions in a different translation unit: -8 snip 8--- // de-inlined class definitions #include iostream #include one_array_only.h using std::cout; bool one_array_only::allocated = false; one_array_only one_array_only::pool[256]; void* one_array_only::operator new[] (std::size_t size) throw() { cout class new[] operator\n; #if WTF return pool;// does not trigger bug #else return NULL;// triggers bug: no operator delete[] called #endif } void one_array_only::operator delete[] (void *p) throw() { cout class delete[] operator\n; } -8 snip 8--- The main translation unit is still calling one_array_only::operator delete[](void*) (from an asm dump). This suggests that one_array_only::operator delete[] is somehow being mis-compiled. Fang -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29164
[Bug c++/29164] Overloaded operator delete[] doesn't get called
--- Comment #4 from bangerth at dealii dot org 2006-10-11 03:43 --- Confirmed. 12.5/4 reads to me as if myclass::operator delete[] should be called. Indeed icc doesn't call either user defined operator in the array case. I think that's just a convergence of bugs, though. This appears to have been broken since at least 2.95. W. -- bangerth at dealii dot org changed: What|Removed |Added CC||bangerth at dealii dot org Status|UNCONFIRMED |NEW Ever Confirmed|0 |1 Keywords||wrong-code Known to fail||2.95.3 3.3.6 4.2.0 Last reconfirmed|-00-00 00:00:00 |2006-10-11 03:43:06 date|| http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29164
[Bug c++/29164] Overloaded operator delete[] doesn't get called
--- Comment #1 from Andreas dot Kowarz at tu-dresden dot de 2006-09-21 10:47 --- *** Bug 29163 has been marked as a duplicate of this bug. *** -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29164
[Bug c++/29164] Overloaded operator delete[] doesn't get called
--- Comment #2 from rguenth at gcc dot gnu dot org 2006-09-21 11:25 --- EDG ends up not even calling the overloaded delete. Looking at the std I can see no reason why your program should not use the overloaded deletes. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29164
[Bug c++/29164] Overloaded operator delete[] doesn't get called
--- Comment #3 from Andreas dot Kowarz at tu-dresden dot de 2006-09-21 11:59 --- (In reply to comment #2) EDG ends up not even calling the overloaded delete. Looking at the std I can see no reason why your program should not use the overloaded deletes. For the moment, I can work around the bug by calling the operator directly, e.g. myclass::operator delete[] (ad)--- (in form of a preprocessor macro). Seems, I should provide macros for all of the four operators since my source code is intended to be compiled with other compilers, too. :-) -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=29164