http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59875

--- Comment #3 from Marc Glisse <glisse at gcc dot gnu.org> ---
(In reply to josephlawrie from comment #2)
> (In reply to Marc Glisse from comment #1)
> Am I correct in understanding this would not be possible without -fno-weak
> or when linking dynamically? In those cases, the function of delete could
> not be know when optimizingm, surely?

My comments were for the version where you uncomment the definitions of new and
delete:

#include <array>
#include <cassert>
#include <cstdlib>

struct P {
    P() : _value(0) {}
    ~P() { if(_value) free(_value); }
   char *_value;
};

int main() {
  if(std::array<P, 4>().size() != 4)
    assert(false);
}


You can look at what happens if you change the size of the array to 1, which
removes the unrolling issue. After unrolling, you get either 4 calls to
operator delete(0), or nothing if you provided your definition of delete.

To let the compiler know that you want the standard operator delete (which does
nothing on 0), I am not sure what should be done. It is a different issue,
which you would need to ask about in a separate PR. The easiest is probably to
use -flto (it has to be used all the way, in particular when building
libsupc++). I think libstdc++ should provide an option to get inline
definitions of those functions (I know the standard forbids them to be inline),
possibly even omitting the new_handler code.

Reply via email to