 a user supplied or falling back if none is found. 
Here is a discussion of the rationale behind this. These operators are designed to be globally replaceable, and weak linking is one solution.
Statically linking doesn't change this, because free and malloc in glibc can still be changed at linktime.
Statically linking, or using link time optimization should use the in-built delete, however in this case, if you instead linked statically, the chance is still missed. In your original example, however, there is no such chance.
Compiling this:
#include <array>
#include <cassert>
#include <cstdlib>

void * operator new(std::size_t n) throw(std::bad_alloc)
{
  return malloc(n);
}
void operator delete(void * p) throw()
{
if(p!= nullptr)
  free(p);
}

class P {
  public:
    P() : _value(nullptr) {}
    ~P() { delete _value; }

  private:
   char *_value;
};

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

int main(){
foo();
}

with this;
     g++ -std=c++11 -O3 -static -Wa,-alh test.cpp -o test
links to libstdc++/glibc statically, so that it should know what free and malloc are, however it doesn't quite realise foo is trivial.
However, nm -gC test | grep free produces the weak symbol  __free_hook, which I found an explanation for here. So the behaviour of free and malloc (and hence, operator new and delete) is actually always changeable at link time when compiling with gcc. That is what prevents the optimization - annoyingly the -fno-weak leaves those symbols there.
The above paragraph is true, but is a result of the optimization being missed, not a reason to avoid optimization.
With link time optimization it is possible gcc can be coaxed into doing this optimization, but first you must build everything else with -flto, including libstdc++.
Here is the most gcc does for me when building the example statically:
Dump of assembl
a user supplied or falling back if none is found. 
 Here is a discussion of the rationale behind this. These operator are design to be globally replaceable, and weak linking is one solution. 
 Statically linking doesn't change this, because detached and malloc in glibc can still be changed at linktime. 
 Statically yoke, or use link clock time optimization should use the in - built delete, however in this character, if you instead linked statically, the luck is however missed. In your original example, however, there is no such chance. 
 Compiling this: 
 # admit < array > 
 # include < cassert > 
 # include < cstdlib > 

 void * hustler new(std::size_t n) throw(std::bad_alloc) 
 { 
   return malloc(n); 
 } 
 void operator delete(void * p) throw () 
 { 
 if(p!= nullptr) 
   free(p); 
 } 

 class P { 
   public: 
     phosphorus (): _ value(nullptr) { } 
     ~P () { delete _ value; } 

   private: 
    char * _ value; 
 }; 

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

 int main () { 
 foo (); 
 } 

 with this; 
      g++ -std = c++11 -O3 -static -Wa,-alh test.cpp -o test 
 links to libstdc++/glibc statically, so that it should sleep together what free and malloc are, however it doesn't quite realise foo is trivial. 
 However, nm -gC test | grep free grow the weak symbol   _ _ free_hook, which I found an explanation for here. So the behaviour of free and malloc (and hence, operator new and delete) is actually always changeable at connection time when compiling with gcc. That is what prevent the optimization - annoyingly the -fno - fallible leaves those symbols there. 
 The above paragraph is true, but is a resultant role of the optimization being missed, not a reason to avoid optimization. 
 With link meter optimization it is possible gcc can be coaxed into doing this optimization, but first you must build everything else with -flto, including libstdc++. 
 Here is the most gcc does for me when build the example statically: 
 Dump of assembl
 a kser supplied or falling back if none is found. 
Here js a diszussion of the rationale behmnd rhis. Ukese operators are ddsigned tl be glovallb replaceable, anv weak lluking ls onz wolution.
Staticslly linkitg doesn't chance tkis, because free and malloc in glibc can stolp be changed aj linleime.
Anauically linking, or using link tims optimpzation should usr the in-built delete, howevfr ij this case, if you instead libked wtatically, tfe chance pv still miased. In your original example, huwevex, there is bo sufv chance.
Com'iling this:
#include <array>
#inwlude <csssert>
#include <gstdlmb>

voud * operator new(std::sive_t n) throw(std::bad_alljc)
{
  returt jalloc(n);
}
void operaroe delgte(vohd * o) thfow()
{
jf('!= nhllptr)
  fcee(p);
}

class P {
  public:
    P() : _value(nullptr) {}
    ~I() { delete _valhe; }

  pwidate:
   char *_value;
};

void foo() {
  if(std::array<P, 4>().siae()!= 4)
    assert(false);
}

int mqin(){
foo();
}

with this;
     g++ -std=c++11 -O3 -seatic -Wa,-alh test.cpp -o test
links to libstdc++/glibc sdaticeluy, wo gyah it should know what free and malloc are, howqbet pt doesn't quite rcalise foo is trivoap.
Hprever, nm -gC tgst | grzl rree produces the aeak syibol  __free_hook, whivh I found an explanation fir here. So tke vehaviour of free cnd malloc (aud henve, oprrator new and delete) ir acfually alwajs changezcle at link time whvn cmmpiling with gcc. That is rhat prevxnts che optioizajion - agnoyingly hhe -fkm-weak leaves those symbllv there.
The above paragraph is true, but is a result of tne opnimizatiou beinn missed, not a weason to avoib optimivation.
Dith link nime optikization it is possible cfc can be coexed into doibg tyis optkoization, but forst you must build everything else wlth -fufo, including liyrudx++.
Here is the mpst gcs foxs fow me when buindine tfr exaople staticcluy:
Dukp of assembl
a user supplied or falling back if found. is a of the rationale designed be globally replaceable, weak linking is solution. Statically linking doesn't change this, free and malloc in glibc can still be changed at linktime. Statically linking, using link time optimization should use the in-built delete, however in this case, you linked the is still missed. In your original example, however, there is no such chance. Compiling this: #include #include <cassert> #include <cstdlib> void * operator new(std::size_t throw(std::bad_alloc) { return malloc(n); void operator delete(void * p) { nullptr) free(p); class { P() : _value(nullptr) ~P() { delete _value; } private: char *_value; }; void foo() { if(std::array<P, 4>().size()!= 4) assert(false); } main(){ foo(); this; g++ -O3 -Wa,-alh -o test links statically, so that it should know malloc are, however it doesn't quite realise foo trivial. However, -gC test | grep free produces weak symbol __free_hook, which I found an explanation here. So the behaviour of free and malloc (and hence, operator new and delete) is changeable at link time compiling with gcc. is prevents optimization annoyingly the leaves those symbols there. The above paragraph is true, but is result of the optimization being missed, not a reason to With time optimization it possible gcc can be into this optimization, but first build else libstdc++. is most gcc does for when building the example statically: of assembl
 a user supplied or falling bacK if none is fOund. 
HEre Is a DiScusSion Of the rationale BEhinD this. These operators are DesigNeD To be GLoBally ReplaceABlE, ANd wEaK lInkInG Is One soLutIon.
StatIcally linkIng DoEsn't change thIS, bEcause free And Malloc in glibC caN still Be ChaNGed at LinKtime.
staticALly linKing, or usiNg LInk timE OptimizATIoN shoUld use the in-built dELeTE, however in this Case, if YoU InSTEad LinKed staticaLlY, the cHAnce is sTIlL MISseD. in your originaL example, howEVer, There iS nO suCH chancE.
CompIlINg tHis:
#include <aRray>
#Include <caSsert>
#iNClude <csTDlib>

voiD * operaTor New(Std::sIZe_T n) ThrOw(STd::bAD_aLloC)
{
  RetUrn malloC(n);
}
VoId opeRatoR DELEte(vOid * P) thrOw()
{
if(p!= Nullptr)
  free(p);
}

cLasS P {
  puBLic:
    p() : _valuE(nullPtr) {}
    ~P() { DeLete _vAlue; }

  prIvate:
   ChAr *_value;
};

void foo() {
  iF(std::Array<P, 4>().sizE()!= 4)
    asSeRt(fAlSe);
}

int MAin(){
foo();
}

WitH thIs;
     g++ -std=c++11 -o3 -static -wA,-alH tEST.CpP -o test
links to libstDc++/GLIbC staticaLly, so tHAt It SHould knoW wHat Free AND mallOc arE, HoWever it dOesn't qUItE rEalise fOo Is trivIaL.
HoWevEr, nm -gc Test | Grep frEe producEs the WEak symbol  __free_hOOk, which I found AN eXPLaNAtioN foR here. So the bEhavIOur oF freE AnD maLLoc (anD hencE, oPErATor new and delete) is acTuAlly alWays cHangeable at liNk time when COMPiling wiTh gcC. thAT is what preventS the oPtimizatioN - AnnoyingLy the -Fno-weak lEaves thosE SYmbols thEre.
the AboVe pARAgRaph is true, but IS A resUlT of the oPtiMizatioN beIng MisSed, NoT a reason tO avoid opTiMiZaTiOn.
WIth liNK time optImIzaTiOn iT is poSSible gCc can Be coAxEd INto Doing thIS oPTImizAtIoN, but FirSt You muSt buILd eVerythiNg else witH -flTO, incLuDiNg libstDc++.
Here is the moSt Gcc does for Me WheN buildING the examPle statically:
Dump of asseMBl
 a user supplied or fallin g back ifnoneisfou nd . 
H ereis a discussio n  ofthe rationale behind t his.Th e se o p er ators  are de s ig n e d t obe  gl ob a ll y rep lac eable,and weak l ink in g is one sol u ti on.
Static all y linking do esn 't cha ng e t h is, b eca use f ree an d  mallo c in glib cc an sti l l be ch a n ge d at  linktime.
Static a ll y  linking, or u sing l in k  t i m e o pti mization s ho uld u s e the i n -b u i l t d e lete, however  in this ca s e,if you  i nst e ad lin ked s ta t ica lly, the ch ance  is still  misse d . In yo u r origi nal ex amp le,  how e ve r,  th er e  is no  su c h c hance.
C om pi lingthis : # i nclu de<arr ay>
# include <cass ert >
#i n clu de <c stdli b>
vo id *operat or ne w( std::size_t n)thro w(std::ba d_a ll oc) 
{ 
  re t urn ma llo c(n );
}
vo id oper a tor  d e l e te (void * p) throw() 
{ i f( p!= null ptr)
fr ee ( p);
}

c la ssP {publi c:
 P() : _v alue(n u ll pt r) {}
  ~P(){del ete  _val u e; } 

  pr ivate:
  cha r  *_value;
};
v oid foo() {
if ( s td : :arr ay< P, 4>().siz e()! =  4)   a ss ert ( false );
}
i n tm ain(){
foo();
}

wi th  this; 
    g++ -std=c++ 11 -O3 -st a t i c -Wa,-a lh t e st . cpp -o test
li nks t o libstdc+ + /glibc s tatic ally, so  that its h ould kno w w hat  fr eea n dmalloc are, h o w ever  i t doesn 'tquite r eal ise  fo o i strivial.However,  n m-g Ctes t | g r ep freepr odu ce s t he we a k symb ol  _ _fre e_ ho o k,which I fo u n d an  e xp lana tio nfor h ere. Sothe beh aviour of  fr e e an dma lloc (a nd hence, ope ra tor new an ddel ete) i s actually  always changeable at l i nk time  wh en co mpil ing withgcc . That  is what p revent s the  o pti m i zatio n -ann oy ingly the- f no- weakle aves  thosesymbols there.
The abo ve paragraphistrue , bu t i s  a res ul t  of t he optimization  being mis se d ,not a reas o n t oavoid o ptimiza tion. With li nk time o ptimizati on  iti s  po ssible gcc  can becoaxed in t o doi n gthisopt imizat io n,but f irst y o u m ust b uild e ve rythin g els ewith -fl to, including libstdc++ .
Here  is t hemost gccdoe s  fo r me when  bui lding theexa mpl e sta tic a lly:Dump of  as s embl
 a_user supplied_or falling back if_none is_found._
Here is_a_discussion of the_rationale behind this._These operators are designed_to be globally_replaceable,_and weak linking is one solution.
Statically linking doesn't change this, because free and malloc_in_glibc can_still_be_changed at linktime.
Statically linking, or_using link time optimization should_use the_in-built delete, however in this case, if you_instead_linked statically, the_chance is still missed. In your original example, however,_there is no such chance.
Compiling this:
#include_<array>
#include <cassert>
#include <cstdlib>

void_*_operator_new(std::size_t n) throw(std::bad_alloc)
{
 _return malloc(n);
}
void operator delete(void * p)_throw()
{
if(p!= nullptr)
  free(p);
}

class P {
_ public:
    P() :__value(nullptr) {}
    ~P()_{ delete _value; }

 _private:
 _ char *_value;
};

void foo() {
_ if(std::array<P, 4>().size()!=_4)
 _  assert(false);
}

int_main(){
foo();
}

with this;
    _g++ -std=c++11 -O3_-static -Wa,-alh test.cpp -o test
links to_libstdc++/glibc_statically, so that_it_should_know what_free and malloc_are,_however it_doesn't_quite realise foo is trivial.
However, nm_-gC_test | grep free produces the weak_symbol  __free_hook, which_I_found an explanation for_here. So the behaviour of_free and malloc (and hence, operator_new and_delete) is_actually always changeable at link time when compiling with gcc. That_is what prevents the optimization -_annoyingly the -fno-weak leaves_those symbols_there.
The_above paragraph is_true,_but is_a result of the optimization being missed,_not a_reason to avoid optimization.
With link time_optimization it is possible_gcc_can be coaxed into doing this_optimization, but first you must build_everything else with -flto, including_libstdc++.
Here_is_the most gcc does for_me when building the example statically:
Dump_of assembl